Part Number Hot Search : 
AD100 PD3016 SCA100 33590JT 50827656 2N4208 MM5450YN 16160
Product Description
Full Text Search
 

To Download PIC16F72013 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2010-2013 microchip technology inc. ds41430d-page 1 pic16(l)f720/721 devices included in this data sheet: high-performance risc cpu: ? only 35 instructions to learn: - all single-cycle instructions except branches ? operating speed: - dc ? 16 mhz oscillator/clock input - dc ? 250 ns instruction cycle ? up to 4k x 14 words of flash program memory ? up to 256 bytes of data memory (ram) ? interrupt capability ? 8-level deep hardware stack ? direct, indirect and relative addressing modes ? processor self-write/read access to program memory special microcontroller features: ? precision internal oscillator: - 16 mhz or 500 khz operation - factory calibrated to 1%, typical - software tunable - software selectable 1, 2, 4 or 8 divider ? power-saving sleep mode ? industrial and extended temperature range ? power-on reset (por) ? power-up timer (pwrt) ? brown-out reset (bor) ? multiplexed master clear with pull-up/input pin ? programmable code protection ? in-circuit serial programming tm (icsp tm ) via two pins ? 128 bytes high-endurance flash: - 100,000 write flash endurance (minimum) ? wide operating voltage range: - 1.8v to 5.5v (pic16f720/721) - 1.8v to 3.6v (pic16lf720/721) low-power features: ? standby current: - 40 na @ 1.8v, typical ? low-power watchdog timer current: - 500 na @ 1.8v, typical peripheral features: ? up to 17 i/o pins and 1 input-only pin: - high-current source/sink for direct led drive - interrupt-on-change pins - individually programmable weak pull-ups ? a/d converter: - 8-bit resolution - 12 channels - selectable voltage reference ? timer0: 8-bit timer/counter with 8-bit programmable prescaler ? enhanced timer1 - 16-bit timer/counter with prescaler - external gate input mode with toggle and single shot modes - interrupt-on-gate completion ? timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler ? capture, compare, pwm module (ccp) - 16-bit capture, max resolution 12.5 ns - 16-bit compare, max resolution 250 ns - 10-bit pwm, max frequency 15 khz ? addressable universal synchronous asynchronous receiver transmitter (ausart) ? synchronous serial port (ssp) - spi (master/slave) -i 2 c tm (slave) with address mask ? pic16f720 ? pic16lf720 ? pic16f721 ? pic16lf721 20-pin flash microcontrollers
pic16(l)f720/721 ds41430d-page 2 ? 2010-2013 microchip technology inc. pic16(l)f72x family types device data sheet index program memory flash (words) data sram (bytes) i/o?s (2) 8-bit adc (ch) capsense (ch) timers (8/16-bit) ausart ssp (i 2 c?/spi) ccp debug (1) xlp pic16(l)f707 (1) 8192 363 36 14 32 4/2 1 1 2 i y pic16(l)f720 (2) 2048 128 18 12 ? 2/1 1 1 1 i ? pic16(l)f721 (2) 4096 256 18 12 ? 2/1 1 1 1 i ? pic16(l)f722 (4) 2048 128 25 11 8 2/1 1 1 2 i y pic16(l)f722a (3) 2048 128 25 11 8 2/1 1 1 2 i y pic16(l)f723 (4) 4096 192 25 11 8 2/1 1 1 2 i y pic16(l)f723a (3) 4096 192 25 11 8 2/1 1 1 2 i y pic16(l)f724 (4) 4096 192 36 14 16 2/1 1 1 2 i y pic16(l)f726 (4) 8192 368 25 11 8 2/1 1 1 2 i y pic16(l)f727 (4) 8192 368 36 14 16 2/1 1 1 2 i y note 1: i - debugging, integrated on chip; h - debugging, requires debug header. 2: one pin is input-only. data sheet index: (unshaded devices are described in this document.) 1: ds41418 pic16(l)f707 data sheet, 40/44-pin flash, 8-bit microcontrollers. 2: ds41430 pic16(l)f720/721 data sheet, 20-pin flash, 8-bit microcontrollers. 3: ds41417 pic16(l)f722a/723a data sheet, 28-pin flash, 8-bit microcontrollers. 4: ds41341 pic16(l)f72x data sheet, 28/40/44-pin flash, 8-bit microcontrollers.
? 2010-2013 microchip technology inc. ds41430d-page 3 pic16(l)f720/721 pin diagrams ? 20-pin diagram for pic16f720/721 and pic16lf720/721 pin diagrams ? 20-pin diagram for pic16f720/721 and pic16lf720/721 pdip, soic, ssop pic16f720/721 pic16lf720/721 1 2 3 4 20 19 18 17 5 6 7 16 15 14 v dd ra5/t1cki/clkin ra4/an3/t1g /clkout ra3/mclr /v pp rc5/ccp1 rc4 rc3/an7 v ss ra0/an0/icspdat ra1/an1/icspclk ra2/an2/t0cki/int rc0/an4 rc1/an5 rc2/an6 8 9 10 13 12 11 rc6/an8/ss rc7/an9/sdo rb7/tx/ck rb4/an10/sdi/sda rb5/an11/rx/dt rb6/sck/scl 2 3 6 1 18 19 20 15 7 16 17 5 4 pic16f720/721 pic16lf720/721 v dd ra5/t1cki/clkin ra4/an3/t1g /clkout ra3/mclr /v pp rc5/ccp1 rc4 rc3/an7 rc6/an8/ss rc7/an9/sdo rb7/tx/ck v ss ra0/an0/icspdat ra1/an1/icspclk ra2/an2/t0cki/int rc0/an4 rc1/an5 rc2/an6 rb4/an10/sdi/sda rb5/an11/rx/dt rb6/sck/scl 8 9 10 11 12 13 14 qfn (4x4)
pic16(l)f720/721 ds41430d-page 4 ? 2010-2013 microchip technology inc. table 1: 20-pin allocatio n table (pic16f720/721 and pic16lf720/721) i/o 20-pin pdip/soic/ ssop 20-pin qfn a/d timers ccp ausart ssp interrupt pull-up basic ra0 19 16 an0 ? ? ? ? ioc y icspdat ra1 18 15 an1 ? ? ? ? ioc y icspclk ra2 17 14 an2 t0cki ? ? ? int/ioc ? ? ra3 4 1 ? ? ? ? ? ioc y mclr /v pp ra4 3 20 an3 t1g ? ? ? ioc y clkout ra5 2 19 ? t1cki ? ? ? ioc y clkin rb4 13 10 an10 ? ? ? sdi/sda ioc y ? rb5 12 9 an11 ? ? rx/dt ? ioc y ? rb6 11 8 ? ? ? ? sck/scl ioc y ? rb7 10 7 ? ? ? tx/ck ? ioc y ? rc0 16 13 an4 ? ? ? ? ? ? ? rc1 15 12 an5 ? ? ? ? ? ? ? rc2 14 11 an6 ? ? ? ? ? ? ? rc3 7 4 an7 ? ? ? ? ? ? ? rc4 6 3 ? ? ? ? ? ? ? ? rc5 5 2 ? ? ccp1 ? ? ? ? ? rc6 8 5 an8 ? ? ? ss ? ? ? rc7 9 6 an9 ? ? ? sdo ? ? ? v dd 1 18 ? ? ? ? ? ? ? v dd vss 20 17 ? ? ? ? ? ? ? v ss
? 2010-2013 microchip technology inc. ds41430d-page 5 pic16(l)f720/721 table of contents 1.0 device overview ............................................................................................................ ............................................................. 7 2.0 memory organization ......................................................................................................... ....................................................... 11 3.0 resets ...................................................................................................................... ................................................................. 25 4.0 interrupts .................................................................................................................. ................................................................. 35 5.0 low dropout (ldo) voltage regulator ......................................................................................... ............................................ 43 6.0 i/o ports ................................................................................................................... ................................................................. 45 7.0 oscillator module........................................................................................................... ............................................................ 65 8.0 device configuration ........................................................................................................ ......................................................... 71 9.0 analog-to-digital converter (adc) module .................................................................................... ........................................... 75 10.0 fixed voltage reference.................................................................................................... ....................................................... 85 11.0 temperature indicator module ............................................................................................... .................................................... 87 12.0 timer0 module .............................................................................................................. ............................................................ 89 13.0 timer1 module with gate control............................................................................................ .................................................. 93 14.0 timer2 module .............................................................................................................. .......................................................... 105 15.0 capture/compare/pwm (ccp) module ........................................................................................... ....................................... 107 16.0 addressable universal synchronous asynchr onous receiver transmitter (ausart) ............................................... ........... 117 17.0 ssp module overview ........................................................................................................ .................................................... 137 18.0 flash program memory self read/self write control.......................................................................... ................................... 159 19.0 power-down mode (sleep) .................................................................................................... ................................................. 167 20.0 in-circuit serial programming? (icsp?) ..................................................................................... ......................................... 169 21.0 instruction set summary .................................................................................................... ..................................................... 171 22.0 development support........................................................................................................ ...................................................... 181 23.0 electrical specifications.................................................................................................. ......................................................... 185 24.0 dc and ac characteristics graphs and charts ................................................................................ ...................................... 211 25.0 packaging information...................................................................................................... ....................................................... 231 appendix a: data sheet revision history........................................................................................ ................................................. 241 appendix b: migrating from other pic ? devices....................................................................................................................... ...... 241 the microchip web site ......................................................................................................... ........................................................... 249 customer change notification service ........................................................................................... .................................................. 249 customer support .............................................................................................................. ............................................................... 249 reader response ................................................................................................................ ............................................................. 250 product identification system .................................................................................................. .......................................................... 251
pic16(l)f720/721 ds41430d-page 6 ? 2010-2013 microchip technology inc. to our valued customers it is our intention to provide our valued customers with the be st documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regardi ng this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
? 2010-2013 microchip technology inc. ds41430d-page 7 pic16(l)f720/721 1.0 device overview the pic16(l)f720/721 devices are covered by this data sheet. they are available in 20-pin packages. figure 1-1 shows a block diagram of the pic16(l)f720/721 devices. table 1-1 shows the pinout descriptions.
pic16(l)f720/721 ds41430d-page 8 ? 2010-2013 microchip technology inc. figure 1-1: 20-pin device bloc k diagram for pic16f720/721 flash program memory 8k x 14 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers 368 x 8 direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg power-on reset watchdog timer instruction decode & control timing generation clkin clkout mclr v dd porta portb portc ra4 rc0 rc1 rc2 rc3 rc4 rc5 rc6 rc7 8 8 brown-out reset ausart timer0 timer1 timer2 ra3 ra1 ra0 8 3 analog-to-digital converter rb6 rb7 v ss t0cki t1g t1cki synchronous sda scl ss sdo serial port sdi / sck/ tx/ck rx/dt internal oscillator block configuration flash program memory 8k x 14 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers 368 x 8 direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer power-on reset watchdog timer instruction decode & control timing generation mclr v dd portb portc rc1 8 8 brown-out reset ausart timer0 timer1 timer2 8 3 v ss t0cki t1cki synchronous sda scl ss sdo serial port sck/ configuration flash program memory (1) 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers (1) direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg instruction decode & control timing generation mclr v dd portb portc ra5 8 8 timer0 timer1 timer2 ra2 8 3 rb4 rb5 v ss t0cki t1cki synchronous sda scl ss sdo serial port sck/ configuration ccp1 ccp1 an9 an0 an1 an2 an3 an4 an8 an10 an11 ldo regulator ausart icspclk icspdat icsp? an6 an5 an7 pmdatl pmadrl self read/ write flash memory note: pic16(l)f720 ? 2k x 14 flash, 128 x 8 ram pic16(l)f721 ? 4k x 14 flash, 256 x 8 ram.
? 2010-2013 microchip technology inc. ds41430d-page 9 pic16(l)f720/721 table 1-1: pinout description name function in out description ra0/an0/icspdat/icddat ra0 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an0 an ? a/d channel 0 input. icspdat st cmos icsp? data i/o. ra1/an1/icspclk/icdclk ra1 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an1 an ? a/d channel 1 input. icspclk st ? icsp? clock. ra2/an2/t0cki/int ra2 ttl cmos general purpose i/o with ioc and wpu. an2 an ? a/d channel 2 input. t0cki st ? timer0 clock input. int st ? external interrupt. ra3/mclr /v pp ra3 ttl ? general purpose input-only with ioc and wpu. mclr st ? master clear with internal pull-up. v pp hv ? programming voltage. ra4/an3/t1g /clkout ra4 ttl cmos general purpose i/o with ioc and wpu. an3 an ? a/d channel 3 input. t1g st ? timer1 gate input. clkout ? cmos f osc /4 output. ra5/t1cki/clkin ra5 ttl cmos general purpose i/o with ioc and wpu. t1cki st ? timer1 clock input. clkin st ? external clock input (ec mode). rb4/an10/sdi/sda rb4 ttl cmos general purpose i/o with ioc and wpu. an10 an ? a/d channel 10 input. sdi st ? spi data input. sda i 2 codi 2 c? data. rb5/an11/rx/dt rb5 ttl cmos general purpose i/o with ioc and wpu. an11 an ? a/d channel 11 input. rx st ? usart asynchronous input. dt st cmos usart synchronous data. rb6/sck/scl rb6 ttl cmos general purpose i/o with ioc and wpu. sck st cmos spi clock. scl i 2 codi 2 c? clock. rb7/tx/ck rb7 ttl cmos general purpose i/o with ioc and wpu. tx ? cmos usart asynchronous transmit. ck st cmos usart synchronous clock. rc0/an4 rc0 st cmos general purpose i/o. an4 an ? a/d channel 4 input. rc1/an5 rc1 st cmos general purpose i/o. an5 an ? a/d channel 5 input. rc2/an6 rc2 st cmos general purpose i/o. an6 an ? a/d channel 6 input. rc3/an7 rc3 st cmos general purpose i/o. an7 an ? a/d channel 7 input. legend: an = analog input or output, cmos = cmos compatible input or output, od = open drain, ttl = ttl compatible input, st = schmitt trigger input with cmos levels, i 2 c? = schmitt trigger input with i 2 c, hv = high voltage, xtal = crystal levels
pic16(l)f720/721 ds41430d-page 10 ? 2010-2013 microchip technology inc. rc4 rc4 st cmos general purpose i/o. rc5/ccp1 rc5 st cmos general purpose i/o. ccp1 st cmos capture/compare/pwm 1. rc6/an8/ss rc6 st cmos general purpose i/o. an8 an ? a/d channel 8 input. ss st ? slave select input. rc7/an9/sdo rc7 st cmos general purpose i/o. an9 an ? a/d channel 9 input. sdo ? cmos spi data output. v dd v dd power ? positive supply. vss vss power ? ground supply. table 1-1: pinout description (continued) name function in out description legend: an = analog input or output, cmos = cmos compatible input or output, od = open drain, ttl = ttl compatible input, st = schmitt trigger input with cmos levels, i 2 c? = schmitt trigger input with i 2 c, hv = high voltage, xtal = crystal levels
? 2010-2013 microchip technology inc. ds41430d-page 11 pic16(l)f720/721 2.0 memory organization 2.1 program memory organization the pic16(l)f720/721 has a 13-bit program counter capable of addressing a 8k x 14 program memory space. ta b l e 2 - 1 shows the memory sizes implemented. accessing a location above these boundaries will cause a wrap-around within the implemented memory space. the reset vector is at 0000h and the interrupt vector is at 0004h. figure 2-1: program memory map and stack for the pic16(l)f720 figure 2-2: program memory map and stack for the pic16(l)f721 table 2-1: device size and addresses device program memory size (words) last program memory address high-endurance flash memory address range (1) pic16f720 pic16lf720 2048 07ffh 0780h-07ffh pic16f721 pic16lf721 4096 0fffh 0f80h-0fffh note 1: high-endurance flash applies to the low byte of each address in the range. pc<12:0> 13 0000h 0004h stack level 1 stack level 8 reset vector interrupt vector call , return retfie, retlw stack level 2 0005h on-chip program memory page 0 07ffh wraps to page 0 wraps to page 0 wraps to page 0 0800h 0fffh 1000h 17ffh 1800h 1fffh pc<12:0> 13 0000h 0004h stack level 1 stack level 8 reset vector interrupt vector call , return retfie, retlw stack level 2 0005h on-chip program memory page 0 page 1 07ffh 0800h 0fffh wraps to page 0 wraps to page 1 1000h 17ffh 1800h 1fffh
pic16(l)f720/721 ds41430d-page 12 ? 2010-2013 microchip technology inc. 2.2 data memory organization the data memory is partitioned into multiple banks which contain the general purpose registers (gprs) and the special function registers (sfrs). bits rp0 and rp1 are bank select bits. rp1 rp0 00 ? bank 0 is selected 01 ? bank 1 is selected 10 ? bank 2 is selected 11 ? bank 3 is selected each bank extends up to 7fh (128 bytes). the lower locations of each bank are reserved for the special function registers. above the special function registers are the general purpose registers, implemented as static ram. all implemented banks contain special function registers. some frequently used special function registers from one bank are mirrored in another bank for code reduction and quicker access.
? 2010-2013 microchip technology inc. ds41430d-page 13 pic16(l)f720/721 2.2.1 general purpose register file the register file is organized as 128 x 8 bits in the pic16(l)f720, 256 x 8 bits in the pic16(l)f721. each register is accessed either directly or indirectly through the file select register (fsr), (refer to section 2.5 ?indirect addressing, indf and fsr registers? ). 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral functions for controlling the desired operation of the device (refer to ta b l e 2 - 2 ). these registers are static ram. the special function registers can be classified into two sets: core and peripheral. the special function registers associated with the ?core? are described in this section. those related to the operation of the peripheral features are described in the section of that peripheral feature.
pic16(l)f720/721 ds41430d-page 14 ? 2010-2013 microchip technology inc. figure 2-3: pic16(l)f720 special function registers file address indf (*) 00h indf (*) 80h indf (*) 100h indf (*) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h 105h ansela 185h portb 06h trisb 86h 106h anselb 186h portc 07h trisc 87h 107h anselc 187h 08h 88h 108h 188h 09h 89h 109h 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch pmdatl 10ch pmcon1 18ch 0dh 8dh pmadrl 10dh pmcon2 18dh tmr1l 0eh pcon 8eh pmdath 10eh 18eh tmr1h 0fh t1gcon 8fh pmadrh 10fh 18fh t1con 10h osccon 90h 110h 190h tmr2 11h osctune 91h 111h 191h t2con 12h pr2 92h 112h 192h sspbuf 13h sspadd/sspmsk 93h 113h 193h sspcon 14h sspstat 94h 114h 194h ccpr1l 15h wpua 95h wpub 115h 195h ccpr1h 16h ioca 96h iocb 116h 196h ccp1con 17h 97h 117h 197h rcsta 18h txsta 98h 118h 198h txreg 19h spbrg 99h 119h 199h rcreg 1ah 9ah 11ah 19ah 1bh 9bh 11bh 19bh 1ch 9ch 11ch 19ch 1dh fvrcon 9dh 11dh 19dh adres 1eh 9eh 11eh 19eh adcon0 1fh adcon1 9fh 11fh 19fh general purpose register 80 bytes 20h general purpose register 32 bytes a0h bfh 120h 1a0h c0h 06fh efh 16fh 1efh access ram 070h accesses 70h ? 7fh f0h accesses 70h ? 7fh 170h accesses 70h ? 7fh 1f0h 7fh ffh 17fh 1ffh bank 0 bank 1 bank 2 bank 3 legend: = unimplemented data memory locations, read as ? 0 ?. * = not a physical register.
? 2010-2013 microchip technology inc. ds41430d-page 15 pic16(l)f720/721 figure 2-4: pic16(l)f721 special function registers legend: = unimplemented data memory locations, read as ? 0 ?. * = not a physical register. file address indf (*) 00h indf (*) 80h indf (*) 100h indf (*) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h 105h ansela 185h portb 06h trisb 86h 106h anselb 186h portc 07h trisc 87h 107h anselc 187h 08h 88h 108h 188h 09h 89h 109h 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch pmdatl 10ch pmcon1 18ch 0dh 8dh pmadrl 10dh pmcon2 18dh tmr1l 0eh pcon 8eh pmdath 10eh 18eh tmr1h 0fh t1gcon 8fh pmadrh 10fh 18fh t1con 10h osccon 90h 110h 190h tmr2 11h osctune 91h 111h 191h t2con 12h pr2 92h 112h 192h sspbuf 13h sspadd/sspmsk 93h 113h 193h sspcon 14h sspstat 94h 114h 194h ccpr1l 15h wpua 95h wpub 115h 195h ccpr1h 16h ioca 96h iocb 116h 196h ccp1con 17h 97h 117h 197h rcsta 18h txsta 98h 118h 198h txreg 19h spbrg 99h 119h 199h rcreg 1ah 9ah 11ah 19ah 1bh 9bh 11bh 19bh 1ch 9ch 11ch 19ch 1dh fvrcon 9dh 11dh 19dh adres 1eh 9eh 11eh 19eh adcon0 1fh adcon1 9fh 11fh 19fh general purpose register 80 bytes 20h 06fh 070h 7fh general purpose register 80 bytes a0h efh general purpose register 80 bytes 120h 16fh 1a0h 1efh access ram accesses 70h ? 7fh f0h ffh accesses 70h ? 7fh 170h 17fh accesses 70h ? 7fh 1f0h 1ffh bank 0 bank 1 bank 2 bank 3
pic16(l)f720/721 ds41430d-page 16 ? 2010-2013 microchip technology inc. table 2-2: special function register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets bank 0 00h ( 2 ) indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 01h tmr0 timer0 module register xxxx xxxx uuuu uuuu 02h ( 2 ) pcl program counter (pc) least significant byte 0000 0000 0000 0000 03h ( 2 ) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 04h ( 2 ) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 05h porta ? ? ra5 ra4 ra3 ra2 ra1 ra0 --xx xxxx --xx xxxx 06h portb rb7 rb6 rb5 rb4 ? ? ? ? xxxx ---- uuuu ---- 07h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu 08h ? unimplemented ? ? 09h ? unimplemented ? ? 0ah ( 1 ),( 2 ) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 0bh ( 2 ) intcon gie peie tmr0ie inte rabie tmr0if intf rabif 0000 000x 0000 000x 0ch pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0dh ? unimplemented ? ? 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 ?t1sync ?tmr1on 0000 -0-0 uuuu -u-u 11h tmr2 timer2 module register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 15h ccpr1l capture/compare/pwm register low byte xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register high byte xxxx xxxx uuuu uuuu 17h ccp1con ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg ausart transmit data register 0000 0000 0000 0000 1ah rcreg ausart receive data register 0000 0000 0000 0000 1bh ? unimplemented ? ? 1ch ? unimplemented ? ? 1dh ? unimplemented ? ? 1eh adres adc result register xxxx xxxx uuuu uuuu 1fh adcon0 ? ? chs3 chs2 chs1 chs0 go/ done adon --00 0000 --00 0000 legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: accessible only when sspm<3:0> = 1001 . 4: this bit is unimplemented and reads as ? 1 ?. 5: see register 6-2 .
? 2010-2013 microchip technology inc. ds41430d-page 17 pic16(l)f720/721 bank 1 80h ( 2 ) indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 81h option_ reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 82h ( 2 ) pcl program counter (pc) least significant byte 0000 0000 0000 0000 83h ( 2 ) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 84h ( 2 ) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 85h (5) trisa ? ? trisa5 trisa4 ? (4) trisa2 trisa1 trisa0 --11 -111 --11 -111 86h trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 1111 ---- 1111 ---- 87h trisc trisc7 trisc6 trisc5 tr isc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 88h ? unimplemented ? ? 89h ? unimplemented ? ? 8ah ( 1 ),( 2 ) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 8bh ( 2 ) intcon gie peie tmr0ie inte rabie tmr0if intf rabif 0000 000x 0000 000x 8ch pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 8dh ? unimplemented ? ? 8eh pcon ? ? ? ? ? ?por bor ---- --qq ---- --uu 8fh t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ done t1gval t1gss1 t1gss0 0000 0x00 uuuu uxuu 90h osccon ? ? ircf1 ircf0 icsl icss ? ? --10 qq-- --10 qq-- 91h osctune ? ? tun5 tun4 tun3 tun2 tun1 tun0 --00 0000 --uu uuuu 92h pr2 timer2 module period register 1111 1111 1111 1111 93h sspadd add<7:0> 0000 0000 0000 0000 93h ( 3 ) sspmsk msk<7:0> 1111 1111 1111 1111 94h sspstat smp cke d/a psr/w ua bf 0000 0000 0000 0000 95h wpua ? ? wpua5 wpua4 wpua3 wpua2 wpua1 wpua0 --11 1111 --11 1111 96h ioca ? ? ioca5 ioca4 ioca3 ioca2 ioca1 ioca0 --00 0000 --00 0000 97h ? unimplemented ? ? 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg brg7 brg6 brg5 b rg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 9ah ? unimplemented ? ? 9bh ? unimplemented ? ? 9ch ? unimplemented ? ? 9dh fvrcon fvrrdy fvren tsen tsrng ? ? adfvr1 adfvr0 q000 --00 q000 --00 9eh ? unimplemented ? ? 9fh adcon1 ? adcs2 adcs1 adcs0 ? ? ? ? -000 ---- -000 ---- table 2-2: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: accessible only when sspm<3:0> = 1001 . 4: this bit is unimplemented and reads as ? 1 ?. 5: see register 6-2 .
pic16(l)f720/721 ds41430d-page 18 ? 2010-2013 microchip technology inc. bank 2 100h ( 2 ) indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 102h ( 2 ) pcl program counter (pc) least significant byte 0000 0000 0000 0000 103h ( 2 ) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 104h ( 2 ) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 105h ? unimplemented ? ? 106h ? unimplemented ? ? 107h ? unimplemented ? ? 108h ? unimplemented ? ? 109h ? unimplemented ? ? 10ah ( 1 ),( 2 ) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 10bh ( 2 ) intcon gie peie tmr0ie inte rabie tmr0if intf rabif 0000 000x 0000 000x 10ch pmdatl program memory read data register low byte xxxx xxxx xxxx xxxx 10dh pmadrl program memory read address register low byte 0000 0000 0000 0000 10eh pmdath ? ? program memory read data register high byte --xx xxxx --xx xxxx 10fh pmadrh ? ? ? program memory read address register high byte ---0 0000 ---0 0000 110h ? unimplemented ? ? 111h ? unimplemented ? ? 112h ? unimplemented ? ? 113h ? unimplemented ? ? 114h ? unimplemented ? ? 115h wpub wpub7 wpub6 wpub5 wpub4 ? ? ? ? 1111 ---- 1111 ---- 116h iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ? 0000 ---- 0000 ---- 117h ? unimplemented ? ? 118h ? unimplemented ? ? 119h ? unimplemented ? ? 11ah ? unimplemented ? ? 11bh ? unimplemented ? ? 11ch ? unimplemented ? ? 11dh ? unimplemented ? ? 11eh ? unimplemented ? ? 11fh ? unimplemented ? ? table 2-2: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: accessible only when sspm<3:0> = 1001 . 4: this bit is unimplemented and reads as ? 1 ?. 5: see register 6-2 .
? 2010-2013 microchip technology inc. ds41430d-page 19 pic16(l)f720/721 bank 3 180h ( 2 ) indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 181h option_ reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 182h ( 2 ) pcl program counter (pc) least significant byte 0000 0000 0000 0000 183h ( 2 ) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 184h ( 2 ) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 185h ansela ? ? ?ansa4 ? ansa2 ansa1 ansa0 ---1 -111 ---1 -111 186h anselb ? ? ansb5 ansb4 ? ? ? ? --11 ---- --11 ---- 187h anselc ansc7 ansc6 ? ? ansc3 ansc2 ansc1 ansc0 11-- 1111 11-- 1111 188h ? unimplemented ? ? 18ah ( 1 ),( 2 ) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 18bh ( 2 ) intcon gie peie tmr0ie inte rabie tmr0if intf rabif 0000 000x 0000 000x 18ch pmcon1 ? (4) cfgs lwlo free ?wrenwrrd 1000 -000 1000 -000 18dh pmcon2 program memory control register 2 (not a physical register) ---- ---- ---- ---- 190h ? unimplemented ? ? 191h ? unimplemented ? ? 192h ? unimplemented ? ? 193h ? unimplemented ? ? 194h ? unimplemented ? ? 195h ? unimplemented ? ? 196h ? unimplemented ? ? 197h ? unimplemented ? ? 198h ? unimplemented ? ? 199h ? unimplemented ? ? 19ah ? unimplemented ? ? 19bh ? unimplemented ? ? 19ch ? unimplemented ? ? 19dh ? unimplemented ? ? 19eh ? unimplemented ? ? 19fh ? unimplemented ? ? table 2-2: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: accessible only when sspm<3:0> = 1001 . 4: this bit is unimplemented and reads as ? 1 ?. 5: see register 6-2 .
pic16(l)f720/721 ds41430d-page 20 ? 2010-2013 microchip technology inc. 2.2.2.1 status register the status register, shown in register 2-1 , contains: ? the arithmetic status of the alu ? the reset status ? the bank select bits for data memory (sram) the status register can be the destination for any instruction, like any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as ? 000u u1uu ? (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register, because these instructions do not affect any status bits. for other instructions not affecting any status bits (refer to section 21.0 ?instruction set summary? ). note 1: the c and dc bits operate as borrow and digit borrow out bits, respectively, in subtraction. register 2-1: status: status register r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdc (1) c (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h-1ffh) 0 = bank 0, 1 (00h-ffh) bit 6-5 rp<1:0>: register bank select bits (used for direct addressing) 00 = bank 0 (00h-7fh) 01 = bank 1 (80h-ffh) 10 = bank 2 (100h-17fh) 11 = bank 3 (180h-1ffh) bit 4 to : time-out bit 1 = after power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/digit borrow bit ( addwf , addlw,sublw,subwf instructions) (1) 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit (1) ( addwf , addlw, sublw, subwf instructions) (1) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow , the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high-order or low-order bit of the source register.
? 2010-2013 microchip technology inc. ds41430d-page 21 pic16(l)f720/721 2.2.2.2 option_reg register the option_reg register, shown in register 2-2 , is a readable and writable register, which contains various control bits to configure: ? software programmable prescaler for the timer0/ wdt ? external ra2/int interrupt ?timer0 ? weak pull-ups on porta or portb note: to achieve a 1:1 prescaler assignment for timer0, assign the prescaler to the wdt by setting the psa bit of the option_reg register to ? 1 ?. refer to section 12.1.3 ?software programmable prescaler? . register 2-2: option_reg: option register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rabpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rabpu : porta or portb pull-up enable bit 1 = porta or portb pull-ups are disabled 0 = porta or portb pull-ups are enabled by individual bits in the wpub register bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of int pin 0 = interrupt on falling edge of int pin bit 5 t0cs: timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (f osc /4) bit 4 t0se: timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value timer0 rate wdt rate
pic16(l)f720/721 ds41430d-page 22 ? 2010-2013 microchip technology inc. 2.2.2.3 pcon register the power control (pcon) register contains flag bits (refer to table 3-4 ) to differentiate between a: ? power-on reset (por ) ? brown-out reset (bor ) ? watchdog timer reset (wdt) ? external mclr reset the pcon register also controls the software enable of the bor. the pcon register bits are shown in register 2-3 . register 2-3: pcon: power control register u-0 u-0 u-0 u-0 u-0 u-0 r/w-q r/w-q ? ? ? ? ? ?por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown q = value depends on condition bit 7-2 unimplemented: read as ? 0 ? bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a power-on reset or brown-out reset occurs)
? 2010-2013 microchip technology inc. ds41430d-page 23 pic16(l)f720/721 2.3 pcl and pclath the program counter (pc) is 13 bits wide. the low byte comes from the pcl register, which is a readable and writable register. the high byte (pc<12:8>) is not directly readable or writable and comes from pclath. on any reset, the pc is cleared. figure 2-5 shows the two situations for the loading of the pc. the upper example in figure 2-5 shows how the pc is loaded on a write to pcl (pclath<4:0> ? pch). the lower example in figure 2-5 shows how the pc is loaded during a call or goto instruction (pclath<4:3> ? pch). figure 2-5: loading of pc in different situations 2.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when perform- ing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note an556, ?implementing a table read? (ds00556). 2.3.2 stack all devices have an 8-level x 13-bit wide hardware stack (refer to figures 2-1 and 2-2 ). the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return , retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 program memory paging all devices are capable of addressing a continuous 8k word block of program memory. the call and goto instructions provide only 11 bits of address to allow branching within any 2k program memory page. when doing a call or goto instruction, the upper two bits of the address are provided by pclath<4:3>. when doing a call or goto instruction, the user must ensure that the page select bits are programmed so that the desired program memory page is addressed. if a return from a call instruction (or interrupt) is executed, the entire 13-bit pc is poped off the stack. therefore, manipulation of the pclath<4:3> bits is not required for the return instructions (which pops the address from the stack). example 2-1 shows the calling of a subroutine in page 1 of the program memory. this example assumes that pclath is saved and restored by the interrupt service routine (if interrupts are used). example 2-1: call of a subroutine in page 1 from page 0 pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu result goto , call opcode<10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl as destination note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call , return , retlw and retfie instructions or the vectoring to an interrupt address. note: the contents of the pclath register are unchanged after a return or retfie instruction is executed. the user must rewrite the contents of the pclath regis- ter for any subsequent subroutine calls or goto instructions. org 500h pagesel sub_p1 ;select page 1 ;(800h-fffh) call sub1_p1 ;call subroutine in : ;page 1 (800h-fffh) : org 900h ;page 1 (800h-fffh) sub1_p1 : ;called subroutine ;page 1 (800h-fffh) : return ;return to ;call subroutine ;in page 0 ;(000h-7ffh)
pic16(l)f720/721 ds41430d-page 24 ? 2010-2013 microchip technology inc. 2.5 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf register. any instruction using the indf register actually accesses data pointed to by the file select register (fsr). reading indf itself indirectly will produce 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit of the status register, as shown in figure 2-6 . a simple program to clear ram location 020h-02fh using indirect addressing is shown in example 2-2 . example 2-2: indirect addressing figure 2-6: direct/indirect addressing movlw 020h ;initialize pointer movwf fsr ;to ram bankisel 020h next clrf indf ;clear indf register incf fsr ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next continue ;yes continue note: for memory map detail, refer to figures 2-3 and 2-4 . data memory indirect addressing direct addressing bank select location select rp1 rp0 6 0 from opcode irp file select register 7 0 bank select location select 00 01 10 11 180h 1ffh 00h 7fh bank 0 bank 1 bank 2 bank 3
? 2010-2013 microchip technology inc. ds41430d-page 25 pic16(l)f720/721 3.0 resets the pic16(l)f720/721 differentiates between various kinds of reset: a) power-on reset (por) b) wdt reset during normal operation c) wdt reset during sleep d) mclr reset during normal operation e) mclr reset during sleep f) brown-out reset (bor) some registers are not affected in any reset condition; their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on: ? power-on reset (por) ?mclr reset ?mclr reset during sleep ?wdt reset ? brown-out reset (bor) most registers are not affected by a wdt wake-up since this is viewed as the resumption of normal operation. to and pd bits are set or cleared differently in different reset situations, as indicated in tab le 3 -5 . these bits are used in software to determine the nature of the reset. a simplified block diagram of the on-chip reset circuit is shown in figure 3-1 . the mclr reset path has a noise filter to detect and ignore small pulses. see section 23.0 ?electrical specifications? for pulse width specifications. figure 3-1: simplified block di agram of on-chip reset circuit mclr /v pp v dd wdt module por wdtosc wdt time-out power-on reset pwrt chip_reset 11-bit ripple counter reset enable pwrt sleep brown-out (1) reset boren clkin note 1: refer to the configuration word register 1 ( register 8-1 ). mclre
pic16(l)f720/721 ds41430d-page 26 ? 2010-2013 microchip technology inc. table 3-1: status bits and their significance por bor to pd condition 0x11 power-on reset or ldo reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 1011 brown-out reset 1101 wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep or interrupt wake-up from sleep table 3-2: reset condition for special registers (2) condition program counter status register pcon register power-on reset 0000h 0001 1xxx ---- --0x mclr reset during normal operation 0000h 000u uuuu ---- --uu mclr reset during sleep 0000h 0001 0uuu ---- --uu wdt reset 0000h 0000 1uuu ---- --uu wdt wake-up pc + 1 uuu0 0uuu ---- --uu brown-out reset 0000h 0001 1uuu ---- --u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- --uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?. note 1: when the wake-up is due to an interrupt and global interrupt enable bit (gie) is set, the return address is pushed on the stack and pc is loaded with the interrupt vector (0004h) after execution of pc + 1. 2: if a status bit is not implemented, that bit will be read as ? 0 ?.
? 2010-2013 microchip technology inc. ds41430d-page 27 pic16(l)f720/721 3.1 mclr the pic16(l)f720/721 has a noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a reset does not drive the mclr pin low. voltages applied to the pin that exceed its specification can result in both mclr resets and excessive current beyond the device specification during the esd event. for this reason, microchip recommends that the mclr pin no longer be tied directly to v dd . the use of an rc network, as shown in figure 3-2 , is suggested. an internal mclr option is enabled by clearing the mclre bit in the configuration word register. when mclre = 0 , the reset signal to the chip is generated internally. when the mclre = 1 , the ra3/mclr pin becomes an external reset input. in this mode, the ra3/mclr pin has a weak pull-up to v dd . in-circuit serial programming? is not affected by selecting the internal mclr option. figure 3-2: recommended mclr circuit 3.2 power-on reset (por) the on-chip por circuit holds the chip in reset until v dd has reached a high enough level for proper operation. a maximum rise time for v dd is required. see section 23.0 ?electrical specifications? for details. if the bor is enabled, the maximum rise time specification does not apply. the bor circuitry will keep the device in reset until v dd reaches v bor (see section 3.5 ?brown-out reset (bor)? ). when the device starts normal operation (exits the reset condition), device operating parameters (i.e., voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. for additional information, refer to application note an607, ?power-up trouble shooting? (ds00607). 3.3 power-up timer (pwrt) the power-up timer provides a fixed 72 ms (nominal) time out on power-up only, from por or brown-out reset. the power-up timer operates from the wdt oscillator. for more information, see section 7.3 ?internal clock modes? . the chip is kept in reset as long as pwrt is active. the pwrt delay allows the v dd to rise to an acceptable level. a configuration bit, pwrte , can disable (if set) or enable (if cleared or pro- grammed) the power-up timer. the power-up timer should be enabled when brown-out reset is enabled, although it is not required. the power-up timer delay will vary from chip-to-chip and vary due to: ?v dd variation ? temperature variation ? process variation see dc parameters for details ( section 23.0 ?electrical specifications? ). 3.4 watchdog timer (wdt) the wdt has the following features: ? shares an 8-bit prescaler with timer0 ? time-out period is from 17 ms to 2.2 seconds, nominal ? enabled by a configuration bit wdt is cleared under certain conditions described in table 3-3 . 3.4.1 wdt oscillator the wdt derives its time base from 31 khz internal oscillator. v dd pic ? mcu mclr r1 10 k ? c1 0.1 ? f note: the power-up timer is enabled by the pwrte bit in the configuration word.
pic16(l)f720/721 ds41430d-page 28 ? 2010-2013 microchip technology inc. 3.4.2 wdt control the wdten bit is located in the configuration word register 1. when set, the wdt runs continuously. the psa and ps<2:0> bits of the option_reg register control the wdt period. see section 12.0 ?timer0 module? for more information. figure 3-3: watchdog ti mer block diagram from tmr0 postscaler 8 ps<2:0> psa to tmr0 1 1 0 0 clock source to t 1 g divide by 512 wdten tmr1ge t1gss = 11 wdten wdt reset low-power wdt osc table 3-3: wdt status conditions wdt wdten = 0 cleared clrwdt command exit sleep + system clock = intosc, extclk
? 2010-2013 microchip technology inc. ds41430d-page 29 pic16(l)f720/721 3.5 brown-out reset (bor) brown-out reset is enabled by programming the boren<1:0> bits in the configuration register. between the por and bor, complete voltage range coverage for execution protection can be implemented. two bits are used to enable the bor. when boren = 11 , the bor is always enabled. when boren = 10 , the bor is enabled, but disabled during sleep. when boren = 0x , the bor is disabled. if v dd falls below v bor for greater than parameter (t bor ) (see section 23.0 ?electrical specifica- tions? ), the brown-out situation will reset the device. this will occur regardless of v dd slew rate. a reset is not ensured to occur if v dd falls below v bor for more than parameter (t bor ). if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be re-initialized. once v dd rises above v bor , the power-up timer will execute a 64 ms reset. figure 3-4: brown -out situations 64 ms (1) v bor v dd internal reset v bor v dd internal reset 64 ms (1) < 64 ms 64 ms (1) v bor v dd internal reset note 1: 64 ms delay only if pwrte bit is programmed to ? 0 ?.
pic16(l)f720/721 ds41430d-page 30 ? 2010-2013 microchip technology inc. 3.6 time-out sequence pwrt time-out is invoked after por has expired. the total time-out will vary based on oscillator configuration and pwrte bit status. for example, in ec mode with pwrte bit = 1 (pwrt disabled), there will be no time- out at all. figure 3-5 , figure 3-6 and figure 3-7 depict time-out sequences. since the time-outs occur from the por pulse, if mclr is kept low long enough, the time-outs will expire. then, bringing mclr high will begin execution immediately (see figure 3-6 ). this is useful for testing purposes or to synchronize more than one pic16(l)f720/721 device operating in parallel. table 3-5 shows the reset conditions for some special registers. 3.7 power control (pcon) register the power control (pcon) register has two status bits to indicate what type of reset that last occurred. bit 0 is bor (brown-out reset). bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor = 0 , indicating that a brown-out has occurred. the bor status bit is a ?don?t care? and is not necessarily predictable if the brown-out circuit is disabled (boren<1:0> = 00 in the configuration word register). bit 1 is por (power-on reset). it is a ? 0 ? on power-on reset and unaffected otherwise. the user must write a ? 1 ? to this bit following a power-on reset. on a subsequent reset, if por is ? 0 ?, it will indicate that a power-on reset has occurred (i.e., v dd may have gone too low). for more information, see section 3.5 ?brown-out reset (bor)? . figure 3-5: time-out sequence on power-up (delayed mclr ): case 1 table 3-4: time-out in various situations oscillator configuration power-up brown-out reset wake-up from sleep pwrte = 0 pwrte = 1 pwrte = 0 pwrte = 1 ec, intosc t pwrt ?t pwrt ?? table 3-5: reset bits and their significance por bor to pd condition 0u11 power-on reset 1011 brown-out reset uu0u wdt reset uu00 wdt wake-up uuuu mclr reset during normal operation uu10 mclr reset during sleep legend: u = unchanged, x = unknown t pwrt v dd mclr internal por pwrt time-out internal reset
? 2010-2013 microchip technology inc. ds41430d-page 31 pic16(l)f720/721 figure 3-6: time-out sequence on power-up (delayed mclr ): case 2 figure 3-7: time-out sequ ence on power-up (mclr with v dd ): case 3 v dd mclr internal por pwrt time-out internal reset t pwrt t pwrt v dd mclr internal por pwrt time-out internal reset
pic16(l)f720/721 ds41430d-page 32 ? 2010-2013 microchip technology inc. table 3-6: initialization condition for registers register address power-on reset/ brown-out reset (1) mclr reset/ wdt reset wake-up from sleep through interrupt/time-out w? xxxx xxxx uuuu uuuu uuuu uuuu indf 00h/80h/ 100h/180h xxxx xxxx xxxx xxxx uuuu uuuu tmr0 01h/101h xxxx xxxx uuuu uuuu uuuu uuuu pcl 02h/82h/ 102h/182h 0000 0000 0000 0000 pc + 1 (3) status 03h/83h/ 103h/183h 0001 1xxx 000q quuu (4) uuuq quuu (4) fsr 04h/84h/ 104h/184h xxxx xxxx uuuu uuuu uuuu uuuu porta 05h --xx xxxx --xx xxxx --uu uuuu portb 06h xxxx ---- xxxx ---- uuuu ---- portc 07h xxxx xxxx xxxx xxxx uuuu uuuu pclath 0ah/8ah/ 10ah/18ah ---0 0000 ---0 0000 ---u uuuu intcon 0bh/8bh/ 10bh/18bh 0000 000x 0000 000x uuuu uuuu (2) pir1 0ch 0000 0000 0000 0000 uuuu uuuu (2) tmr1l 0eh xxxx xxxx uuuu uuuu uuuu uuuu tmr1h 0fh xxxx xxxx uuuu uuuu uuuu uuuu t1con 10h 0000 -0-0 0000 -0-0 uuuu -u-u tmr2 11h 0000 0000 0000 0000 uuuu uuuu t2con 12h -000 0000 -000 0000 -uuu uuuu sspbuf 13h xxxx xxxx xxxx xxxx uuuu uuuu sspcon 14h 0000 0000 0000 0000 uuuu uuuu ccpr1l 15h xxxx xxxx xxxx xxxx uuuu uuuu ccpr1h 16h xxxx xxxx xxxx xxxx uuuu uuuu ccp1con 17h --00 0000 --00 0000 --uu uuuu rcsta 18h 0000 000x 0000 000x uuuu uuuu txreg 19h 0000 0000 0000 0000 uuuu uuuu rcreg 1ah 0000 0000 0000 0000 uuuu uuuu adres 1eh xxxx xxxx uuuu uuuu uuuu uuuu adcon0 1fh --00 0000 --00 0000 --uu uuuu option_reg 81h/181h 1111 1111 1111 1111 uuuu uuuu trisa 85h --11 -111 --11 -111 --uu -uuu trisb 86h 1111 ---- 1111 ---- uuuu ---- trisc 87h 1111 1111 1111 1111 uuuu uuuu pie1 8ch 0000 0000 0000 0000 uuuu uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 3-8 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u .
? 2010-2013 microchip technology inc. ds41430d-page 33 pic16(l)f720/721 pcon 8eh ---- --qq ---- --uu (1,5) ---- --uu t1gcon 8fh 0000 0x00 uuuu uxuu uuuu uxuu osccon 90h --10 qq-- --10 qq-- --uu qq-- osctune 91h --00 0000 --uu uuuu --uu uuuu pr2 92h 1111 1111 1111 1111 uuuu uuuu sspadd 93h 0000 0000 0000 0000 uuuu uuuu sspmsk 93h 1111 1111 1111 1111 uuuu uuuu sspstat 94h 0000 0000 0000 0000 uuuu uuuu wpub 115h 1111 ---- 1111 ---- uuuu ---- wpua 95h --11 1111 --11 1111 --uu uuuu iocb 116h 0000 ---- 0000 ---- uuuu ---- ioca 96h --00 0000 --00 0000 --uu uuuu txsta 98h 0000 -010 0000 -010 uuuu -uuu spbrg 99h 0000 0000 0000 0000 uuuu uuuu fvrcon 9dh q000 --00 q000 --00 uuuu --uu adcon1 9fh -000 ---- -000 ---- -uuu ---- pmdatl 10ch xxxx xxxx xxxx xxxx uuuu uuuu pmadrl 10dh 0000 0000 0000 0000 uuuu uuuu pmdath 10eh --xx xxxx --xx xxxx --uu uuuu pmadrh 10fh ---0 0000 ---0 0000 ---u uuuu ansela 185h ---1 -111 ---1 -111 ---u -uuu anselb 186h --11 ---- --11 ---- --uu ---- anselc 187h 11-- 1111 11-- 1111 uu-- uuuu pmcon1 18ch 1000 -000 1000 -000 1000 -000 table 3-6: initialization condition for registers (continued) register address power-on reset/ brown-out reset (1) mclr reset/ wdt reset wake-up from sleep through interrupt/time-out legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 3-8 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u .
pic16(l)f720/721 ds41430d-page 34 ? 2010-2013 microchip technology inc. table 3-7: initialization condition for special registers condition program counter status register pcon register power-on reset 0000h 0001 1xxx ---- --0x mclr reset during normal operation 0000h 000u uuuu ---- --uu mclr reset during sleep 0000h 0001 0uuu ---- --uu wdt reset 0000h 0000 uuuu ---- --uu wdt wake-up pc + 1 uuu0 0uuu ---- --uu brown-out reset 0000h 0001 1xxx ---- --10 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- --uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?. note 1: when the wake-up is due to an interrupt and global interrupt enable bit (gie) is set, the pc is loaded with the interrupt vector (0004h) after execution of pc + 1. table 3-8: summary of registers associated with resets name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page status irp rp1 rp0 to pd z dc c 20 pcon ? ? ? ? ? ?por bor 22 legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. shaded cells are not used by resets. note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation.
? 2010-2013 microchip technology inc. ds41430d-page 35 pic16(l)f720/721 4.0 interrupts the pic16(l)f720/721 device family features an interruptible core, allowing certain events to preempt normal program flow. an interrupt service routine (isr) is used to determine the source of the interrupt and act accordingly. some interrupts can be configured to wake the mcu from sleep mode. the pic16(l)f720/721 device family has 11 interrupt sources, differentiated by corresponding interrupt enable and flag bits: ? timer0 overflow interrupt ? external edge detect on int pin interrupt ? interrupt-on-change, porta and portb pins ? timer1 gate interrupt ? a/d conversion complete interrupt ? ausart receive interrupt ? ausart transmit interrupt ? ssp event interrupt ? ccp1 event interrupt ? timer2 match with pr2 interrupt ? timer1 overflow interrupt a block diagram of the interrupt logic is shown in figure 4-1 . figure 4-1: interrupt logic tmr0if tmr0ie intf inte rabif rabie gie peie wake-up (if in sleep mode) (1) interrupt to cpu tmr1gie tmr1gif adif adie ccp1if ccp1ie ioc-rb4 iocb4 ioc-rb5 iocb5 ioc-rb6 iocb6 ioc-rb7 iocb7 rcif rcie tmr2ie tmr2if sspie sspif txie txif tmr1ie tmr1if note 1: some peripherals depend upon the system clock for operation. since the system clock is suspended during sleep, these peripherals will not wake the part from sleep. see section 19.1 ?wake-up from sleep? . ioc-ra3 ioca3 ioc-ra4 ioca4 ioc-ra5 ioca5 ioc-ra1 ioca1 ioc-ra2 ioca2 ioc-ra0 ioca0
pic16(l)f720/721 ds41430d-page 36 ? 2010-2013 microchip technology inc. 4.1 operation interrupts are disabled upon any device reset. they are enabled by setting the following bits: ? gie bit of the intcon register ? interrupt enable bit(s) for the specific interrupt event(s) ? peie bit of the intcon register (if the interrupt enable bit of the interrupt event is contained in the pie1 register) the intcon and pir1 registers record individual interrupts via interrupt flag bits. interrupt flag bits will be set, regardless of the status of the gie, peie and individual interrupt enable bits. the following events happen when an interrupt event occurs while the gie bit is set: ? current prefetched instruction is flushed ? gie bit is cleared ? current program counter (pc) is pushed onto the stack ? pc is loaded with the interrupt vector 0004h the isr determines the source of the interrupt by polling the interrupt flag bits. the interrupt flag bits must be cleared before exiting the isr to avoid repeated interrupts. because the gie bit is cleared, any interrupt that occurs while executing the isr will be recorded through its interrupt flag, but will not cause the processor to redirect to the interrupt vector. the retfie instruction exits the isr by popping the previous address from the stack and setting the gie bit. for additional information on a specific interrupt?s operation, refer to its peripheral chapter. 4.2 interrupt latency interrupt latency is defined as the time from when the interrupt event occurs to the time code execution at the interrupt vector begins. the latency for synchronous interrupts is three instruction cycles. for asynchronous interrupts, the latency is three to four instruction cycles, depending on when the interrupt occurs. see figure 4-2 for timing details. figure 4-2: int pin interrupt timing note 1: individual interrupt flag bits are set, regardless of the state of any other enable bits. 2: all interrupts will be ignored while the gie bit is cleared. any interrupt occurring while the gie bit is clear will be serviced when the gie bit is set again. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 clkin clkout int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed interrupt latency pc pc + 1 pc + 1 0004h 0005h inst (0004h) inst (0005h) dummy cycle inst (pc) inst (pc + 1) inst (pc ? 1) inst (0004h) dummy cycle inst (pc) ? note 1: intf flag is sampled here (every q1). 2: asynchronous interrupt latency = 3-4 t cy . synchronous latency = 3 t cy , where t cy = instruction cycle time. latency is the same whether inst (pc) is a single cycle or a 2-cycle instruction. 3: clkout is available only in intosc and rc oscillator modes. 4: for minimum width of int pulse, refer to ac specifications in section 23.0 ?electrical specifications? . 5: intf is enabled to be set any time during the q4-q1 cycles. (1) (2) (3) (4) (5) (1)
? 2010-2013 microchip technology inc. ds41430d-page 37 pic16(l)f720/721 4.3 interrupts during sleep some interrupts can be used to wake from sleep. to wake from sleep, the peripheral must be able to operate without the system clock. the interrupt source must have the appropriate interrupt enable bit(s) set prior to entering sleep. on waking from sleep, if the gie bit is also set, the processor will branch to the interrupt vector. otherwise, the processor will continue executing instructions after the sleep instruction. the instruction directly after the sleep instruction will always be executed before branching to the isr. refer to the section 19.0 ?power-down mode (sleep)? for more details. 4.4 int pin the external interrupt, int pin, causes an asynchronous, edge-triggered interrupt. the intedg bit of the option_reg regist er determines on which edge the interrupt will occur. when the intedg bit is set, the rising edge will cause the interrupt. when the intedg bit is clear, the falling edge will cause the interrupt. the intf bit of the intcon register will be set when a valid edge appears on the int pin. if the gie and inte bits are also set, the processor will redirect program execution to the interrupt vector. this interrupt is disabled by clearing the inte bit of the intcon register. 4.5 context saving when an interrupt occurs, only the return pc value is saved to the stack. if the isr modifies or uses an instruction that modifies key registers, their values must be saved at the beginning of the isr and restored when the isr completes. this prevents instructions following the isr from using invalid data. examples of key registers include the w, status, fsr and pclath registers. the code shown in example 4-1 can be used to do the following. ? save the w register ? save the status register ? save the pclath register ? execute the isr program ? restore the pclath register ? restore the status register ? restore the w register since most instructions modify the w register, it must be saved immediately upon entering the isr. the swapf instruction is used when saving and restoring the w and status registers because it will not affect any bits in the status register. it is useful to place w_temp in shared memory because the isr cannot predict which bank will be selected when the interrupt occurs. the processor will branch to the interrupt vector by loading the pc with 0004h. the pclath register will remain unchanged. this requires the isr to ensure that the pclath register is set properly before using an instruction that causes pclath to be loaded into the pc. see section 2.3 ?pcl and pclath? for details on pc operation. example 4-1: saving w, status and pclath registers in ram note: the microcontroller does not normally require saving the pclath register. however, if computed goto s are used, the pclath register must be saved at the beginning of the isr and restored when the isr is complete to ensure correct program flow. movwfw_temp ;copy w to w_temp register swapfstatus,w ;swap status to be saved into w ;swaps are used because they do not affect the status bits bankselstatus_temp ;select regardless of current bank movwfstatus_temp ;copy status to bank zero status_temp register movf pclath,w ;copy pclath to w register movwf pclath_temp ;copy w register to pclath_temp : :(isr) ;insert user code here : bankselstatus_temp ;select regardless of current bank movf pclath_temp,w ; movwf pclath ;restore pclath swapfstatus_temp,w ;swap status_temp register into w ;(sets bank to original state) movwfstatus ;move w into status register swapfw_temp,f ;swap w_temp swapfw_temp,w ;swap w_temp into w
pic16(l)f720/721 ds41430d-page 38 ? 2010-2013 microchip technology inc. 4.5.1 intcon register the intcon register is a readable and writable register, which contains the various enable and flag bits for tmr0 register overflow, portb change and external ra2/int pin interrupts. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie of the intcon register. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. register 4-1: intcon: interrupt control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie tmr0ie inte rabie (1) tmr0if (2) intf rabif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie: peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 tmr0ie: timer0 overflow interrupt enable bit 1 = enables the timer0 interrupt 0 = disables the timer0 interrupt bit 4 inte: int external interrupt enable bit 1 = enables the int external interrupt 0 = disables the int external interrupt bit 3 rabie: porta or portb change interrupt enable bit (1) 1 = enables the porta or portb change interrupt 0 = disables the porta or portb change interrupt bit 2 tmr0if: timer0 overflow interrupt flag bit (2) 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf: int external interrupt flag bit 1 = the int external interrupt occurred (must be cleared in software) 0 = the int external interrupt did not occur bit 0 rabif: porta or portb change interrupt flag bit 1 = when at least one of the porta or portb general purpose i/o pins changed state (must be cleared in software) 0 = none of the porta or portb general purpose i/o pins have changed state note 1: the appropriate bits in the iocb register must also be set. 2: tmr0if bit is set when timer0 rolls over. timer0 is unchanged on reset and should be initialized before clearing tmr0if bit.
? 2010-2013 microchip technology inc. ds41430d-page 39 pic16(l)f720/721 4.5.2 pie1 register the pie1 register contains the interrupt enable bits, as shown in register 4-2 . note: bit peie of the intcon register must be set to enable any peripheral interrupt. register 4-2: pie1: peripheral interrupt enable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr1gie: timer1 gate interrupt enable bit 1 = enable the timer1 gate acquisition complete interrupt 0 = disable the timer1 gate acquisition complete interrupt bit 6 adie: a/d converter (adc) interrupt enable bit 1 = enables the adc interrupt 0 = disables the adc interrupt bit 5 rcie: usart receive interrupt enable bit 1 = enables the usart receive interrupt 0 = disables the usart receive interrupt bit 4 txie: usart transmit interrupt enable bit 1 = enables the usart transmit interrupt 0 = disables the usart transmit interrupt bit 3 sspie: synchronous serial port (ssp) interrupt enable bit 1 = enables the ssp interrupt 0 = disables the ssp interrupt bit 2 ccp1ie: ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enables the timer2 to pr2 match interrupt 0 = disables the timer2 to pr2 match interrupt bit 0 tmr1ie: timer1 overflow interrupt enable bit 1 = enables the timer1 overflow interrupt 0 = disables the timer1 overflow interrupt
pic16(l)f720/721 ds41430d-page 40 ? 2010-2013 microchip technology inc. 4.5.3 pir1 register the pir1 register contains the interrupt flag bits, as shown in register 4-3 . note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie of the intcon register. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. register 4-3: pir1: peripheral interrupt request register 1 r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr1gif: timer1 gate interrupt flag bit 1 = timer1 gate is inactive 0 = timer1 gate is active bit 6 adif: a/d converter interrupt flag bit 1 = a/d conversion complete (must be cleared in software) 0 = a/d conversion has not completed or has not been started bit 5 rcif: usart receive interrupt flag bit 1 = the usart receive buffer is full (cleared by reading rcreg) 0 = the usart receive buffer is not full bit 4 txif: usart transmit interrupt flag bit 1 = the usart transmit buffer is empty (cleared by writing to txreg) 0 = the usart transmit buffer is full bit 3 sspif: synchronous serial port (ssp) interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if: ccp1 interrupt flag bit capture mode : 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode : 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode : unused in this mode bit 1 tmr2if: timer2 to pr2 interrupt flag bit 1 = a timer2 to pr2 match occurred (must be cleared in software) 0 = no timer2 to pr2 match occurred bit 0 tmr1if: timer1 overflow interrupt flag bit 1 = the tmr1 register overflowed (must be cleared in software) 0 = the tmr1 register did not overflow
? 2010-2013 microchip technology inc. ds41430d-page 41 pic16(l)f720/721 table 4-1: summary of registers associated with interrupts name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 option_reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 21 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 legend: - = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the capture, compare and pwm.
pic16(l)f720/721 ds41430d-page 42 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 43 pic16(l)f720/721 5.0 low dropout (ldo) voltage regulator the pic16f720/721 devices differ from the pic16lf720/721 devices due to an internal low dropout (ldo) voltage regulator. the pic16f720/721 contain an internal ldo, while the pic16lf720/721 do not. the lithography of the die allows a maximum operating voltage of 3.6v on the internal digital logic. in order to continue to support 5.0v designs, a ldo voltage regulator is integrated on the die. the ldo voltage regulator allows for the internal digital logic to operate at 3.2v, while i/o?s operate at 5.0v (v dd ).
pic16(l)f720/721 ds41430d-page 44 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 45 pic16(l)f720/721 6.0 i/o ports there are as many as eighteen general purpose i/o pins available. depending on which peripherals are enabled, some or all of the pins may not be available as general purpose i/o. in general, when a peripheral is enabled, the associated pin may not be used as a general purpose i/o pin. 6.1 porta and trisa registers porta is a 8-bit wide, bidirectional port. the corresponding data direction register is trisa ( register 6-2 ). setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., disable the output driver). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., enables output driver and puts the contents of the output latch on the selected pin). example 6-1 shows how to initialize porta. reading the porta register ( register 6-1 ) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisa register ( register 6-2 ) controls the porta pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisa register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 6-1: initializing porta 6.1.1 weak pull-ups each of the porta pins has an individually configurable internal weak pull-up. control bits wpua<5:0> enable or disable each pull-up (see register 6-5 ). each weak pull-up is automatically turned off when the port pin is configured as an output. all pull-ups are disabled on a power-on reset by the rabpu bit of the option_reg register. 6.1.2 interrupt-on-change all of the porta pins are individually configurable as an interrupt-on-change pin. control bits ioca<5:0> enable or disable the interrupt function for each pin (see register 6-6 ). the interrupt-on-change feature is disabled on a power-on reset. for enable interrupt-on-change pins, the present value is compared with the old value latched on the last read of porta to determine which bits have changed or mismatched the old value. the ?mismatch? outputs of the last read are or?d together to set the porta change interrupt flag bit (rabif) in the intcon register. this interrupt can wake the device from sleep. the user, in the interrupt service routine, clears the interrupt by: 1. any read or write of porta. this will end the mismatch condition. 2. clear the flag bit rabif. a mismatch condition will continue to set flag bit rabif. reading or writing porta will end the mismatch condition and allow flag bit rabif to be cleared. the latch holding the last read value is not affected by a mclr or brown-out reset. after these resets, the rabif flag will continue to be set if a mismatch is present. note: the ansela register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. banksel porta ; clrf porta ;init porta banksel ansela ; clrf ansela ;digital i/o banksel trisa ; movlw 0ch ;set ra<3:2> as inputs movwf trisa ;and set ra<5:4,1:0> ;as outputs note: when a pin change occurs at the same time as a read operation on porta, the rabif flag will always be set. if multiple porta pins are configured for the inter- rupt-on-change, the user may not be able to identify which pin changed state.
pic16(l)f720/721 ds41430d-page 46 ? 2010-2013 microchip technology inc. register 6-1: porta: porta register u-0 u-0 r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u ? ? ra5 ra4 ra3 (1) ra2 ra1 ra0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 ra<5:0>: porta i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il note 1: ra<3> is input only. register 6-2: trisa: porta tri-state register u-0 u-0 r/w-1 r/w-1 u-1 r/w-1 r/w-1 r/w-1 ? ? trisa5 trisa4 ? (1) trisa2 trisa1 trisa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 trisa<5:4>: porta tri-state control bit 1 = porta pin configured as an input (tri-stated) 0 = porta pin configured as an output bit 3 unimplemented: read as ? 1 ? bit 2-0 trisa<2:0>: porta tri-state control bit 1 = porta pin configured as an input (tri-stated) 0 = porta pin configured as an output note 1: trisa<3> is unimplemented and read as 1 . register 6-3: wpua: weak pull-up porta register u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? ?wpua5wpua4 wpua3 (2) wpua2 wpua1 wpua0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 wpua<5:0>: weak pull-up porta control bits 1 = weak pull-up enabled (1) 0 = weak pull-up disabled note 1: enabling weak pull-ups also requires that the rabpu bit of the option_reg register be cleared. 2: if mclren = 1 , wpua3 is always enabled.
? 2010-2013 microchip technology inc. ds41430d-page 47 pic16(l)f720/721 6.1.3 ansela register the ansela register ( register 6-5 ) is used to configure the input mode of an i/o pin to analog. setting the appropriate ansela bit high will cause all digital reads on the pin to be read as ? 0 ? and allow analog functions on the pin to operate correctly. the state of the ansela bits has no affect on digital output functions. a pin with tris clear and ansel set will still operate as a digital output, but the input mode will be analog. this can cause unexpected behavior when executing read-modify-write instructions on the affected port. register 6-4: ioca: interrupt-on-change porta register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ioca5 ioca4 ioca3 ioca2 ioca1 ioca0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 ioca<5:0>: interrupt-on-change porta control bits 1 = interrupt-on-change enabled (1) 0 = interrupt-on-change disabled note 1: interrupt-on-change also requires that the ra bie bit of the intcon register be set. register 6-5: ansela: porta analog select register u-0 u-0 u-0 r/w-1 u-0 r/w-1 r/w-1 r/w-1 ? ? ? ansa4 ? ansa2 ansa1 ansa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ansa4 : analog select between analog or digital function on pin ra<4> 0 = digital i/o. pin is assigned to port or digital special function. 1 = analog input. pin is assigned as analog input (1) . digital input buffer is disabled. bit 3 unimplemented: read as ? 0 ? bit 2-0 ansa<2:0> : analog select between analog or digital function on pins ra<2:0>, respectively 0 = digital i/o. pin is assigned to port or digital special function. 1 = analog input. pin is assigned as analog input (1) . digital input buffer is disabled. note 1: setting a pin to an analog input automatically disables the digital input circuitry. weak pull-ups, if available, are unaffected. the corresponding tris bit must be set to input mode by the user in order to allow external control of the voltage on the pin.
pic16(l)f720/721 ds41430d-page 48 ? 2010-2013 microchip technology inc. 6.1.4 pin descriptions and diagrams each porta pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the a/d conver ter (adc), refer to the appropriate section in this data sheet. 6.1.4.1 ra0/an0/icspdat figure 6-1 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the adc ? icsp programming data (separate controls from trisa) ? icd debugging data (separate controls from trisa) 6.1.4.2 ra1/an1/icspclk figure 6-2 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the adc ? icsp programming clock (separate controls from trisa) ? icd debugging clock (separate controls from trisa) 6.1.4.3 ra2/an2/t0cki/int figure 6-3 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the adc ? external interrupt ? clock input for timer0 the timer0 clock input function works independently of any tris register setting. effectively, if trisa2 = 0 , the porta2 register bit will output to the pad and clock timer0 at the same time. 6.1.4.4 ra3/mclr /v pp figure 6-4 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? master clear reset with weak pull-up 6.1.4.5 ra4/an3/t1g /clkout figure 6-5 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the adc ? timer1 gate input ? clock output 6.1.4.6 ra5/t1cki/clkin figure 6-6 shows the diagram for this pin. this pin is configurable to function as one of the following: ? general purpose i/o ? timer1 clock input ? clock input
? 2010-2013 microchip technology inc. ds41430d-page 49 pic16(l)f720/721 figure 6-1: blo ck diagram of ra0 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak rd porta rd wr wr rd wr ioca rd ioca interrupt-on-change analog (1) input mode rabpu analog (1) input mode q3 wr rd wpua data bus wpua porta trisa trisa porta note 1: ansel determines analog input mode. to a/d converter icsp? mode debug 0 1 1 0 0 1 0 1 tris_icddat port_icddat icspdat
pic16(l)f720/721 ds41430d-page 50 ? 2010-2013 microchip technology inc. figure 6-2: blo ck diagram of ra1 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpua rd wpua rd porta rd porta wr porta wr trisa rd trisa wr ioca rd ioca interrupt-on-change analog (1) input mode rabpu analog (1) input mode q3 note 1: ansel determines analog input mode. to a/d converter icsp? mode debug 0 1 1 0 0 1 0 1 tris_icdclk port_icdclk icspclk
? 2010-2013 microchip technology inc. ds41430d-page 51 pic16(l)f720/721 figure 6-3: blo ck diagram of ra2 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak analog (1) input mode data bus wr wpua rd wpua rd porta wr porta wr trisa rd trisa wr ioca rd ioca to a/d converter to i n t to timer0 analog (1) input mode rabpu rd porta interrupt-on- change q3 note 1: ansel determines analog input mode. to voltage regulator (for pic16f720/721 only)
pic16(l)f720/721 ds41430d-page 52 ? 2010-2013 microchip technology inc. figure 6-4: block diag ram of ra3 figure 6-5: block diagram of ra4 input v ss d q ck q d en q data bus rd porta rd porta wr ioca rd ioca reset mclre rd trisa v ss d en q mclre v dd weak mclre interrupt-on- change pin q3 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak analog input mode data bus wr wpua rd wpua rd porta wr porta wr trisa rd trisa wr ioca rd ioca f osc /4 to a/d converter clkout 0 1 clkout enable enable analog (2) input mode rabpu rd porta to t 1 g intosc/ rc/ec (1) clk modes clkout enable note 1: with clkout option. 2: ansel determines analog input mode. interrupt-on- change q3
? 2010-2013 microchip technology inc. ds41430d-page 53 pic16(l)f720/721 figure 6-6: blo ck diagram of ra5 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpua rd wpua rd porta wr porta wr trisa rd trisa wr ioca rd ioca to tmr1 or clkin intosc mode rd porta intosc mode rabpu interrupt-on- change q3 table 6-1: summary of regist ers associated with porta name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page ansela ? ? ? ansa4 ? ansa2 ansa1 ansa0 47 option_reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 21 porta ? ? ra5 ra4 ra3 ra2 ra1 ra0 46 trisa ? ? trisa5 trisa4 ? trisa2 trisa1 trisa0 46 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by porta.
pic16(l)f720/721 ds41430d-page 54 ? 2010-2013 microchip technology inc. 6.2 portb and trisb registers portb is an 8-bit wide, bidirectional port. the corresponding data direction register is trisb ( register 6-7 ). setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). example 6-2 shows how to initialize portb. reading the portb register ( register 6-6 ) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisb register ( register 6-7 ) controls the portb pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisb register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 6-2 shows how to initialize portb. example 6-2: initializing portb 6.2.1 anselb register the anselb register ( register 6-10 ) is used to configure the input mode of an i/o pin to analog. setting the appropriate anselb bit high will cause all digital reads on the pin to be read as ? 0 ? and allow analog functions on the pin to operate correctly. the state of the anselb bits has no affect on digital output functions. a pin with tris clear and anselb set will still operate as a digital output, but the input mode will be analog. this can cause unexpected behavior when executing read-modify-write instructions on the affected port. 6.2.2 weak pull-ups each of the portb pins has an individually configurable internal weak pull-up. control bits wpub<7:4> enable or disable each pull-up (see register 6-8 ). each weak pull- up is automatically turned off when the port pin is configured as an output. all pull-ups are disabled on a power-on reset by the r a bpu bit of the option_reg register. 6.2.3 interrupt-on-change all of the portb pins are individually configurable as an interrupt-on-change pin. control bits iocb<7:4> enable or disable the interrupt function for each pin. refer to register 6-9 . the interrupt-on-change feature is disabled on a power-on reset. for enabled interrupt-on-change pins, the present value is compared with the old value latched on the last read of portb to determine which bits have changed or mismatched the old value. the ?mismatch? outputs of the last read are or?d together to set the portb change interrupt flag bit (rabif) in the intcon register. this interrupt can wake the device from sleep. the user, in the interrupt service routine, clears the interrupt by: a) any read or write of portb. this will end the mismatch condition. b) clear the flag bit rabif. a mismatch condition will continue to set flag bit rabif. reading or writing portb will end the mismatch condition and allow flag bit rabif to be cleared. the latch holding the last read value is not affected by a mclr nor brown-out reset. after these resets, the rabif flag will continue to be set if a mismatch is present. note: the anselb register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. banksel portb ; clrf portb ;init portb banksel anselb clrf anselb ;make rb<7:4> digital banksel trisb ; movlw b ? 11110000 ? ;set rb<7:4> as inputs movwf trisb ; note: when a pin change occurs at the same time as a read operation on portb, the rabif flag will always be set. if multiple portb pins are configured for the interrupt-on-change, the user may not be able to identify which pin changed state.
? 2010-2013 microchip technology inc. ds41430d-page 55 pic16(l)f720/721 register 6-6: port b: portb register r/w-x/u r/w-x/u r/w-x/u r/w-x/u u-0 u-0 u-0 u-0 rb7 rb6 rb5 rb4 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 rb<7:4> : portb i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il bit 3-0 unimplemented: read as ? 0 ? register 6-7: trisb: po rtb tri-state register r/w-1 r/w-1 r/w-1 r/w-1 u-0 u-0 u-0 u-0 trisb7 trisb6 trisb5 trisb4 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 trisb<7:4>: portb tri-state control bit 1 = portb pin configured as an input (tri-stated) 0 = portb pin configured as an output bit 3-0 unimplemented: read as ? 0 ? register 6-8: wpub: weak pull-up portb register r/w-1 r/w-1 r/w-1 r/w-1 u-0 u-0 u-0 u-0 wpub7 wpub6 wpub5 wpub4 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 wpub<7:4> : weak pull-up portb control bits 1 = weak pull-up enabled (1,2) 0 = weak pull-up disabled bit 3-0 unimplemented: read as ? 0 ? note 1: global r a bpu bit of the option_reg register must be cleared for individual pull-ups to be enabled. 2: the weak pull-up device is automatically disabled if the pin is in configured as an output.
pic16(l)f720/721 ds41430d-page 56 ? 2010-2013 microchip technology inc. register 6-9: iocb: interrup t-on-change portb register r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 iocb7 iocb6 iocb5 iocb4 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 iocb<7:4>: interrupt-on-change portb control bits 1 = interrupt-on-change enabled (1) 0 = interrupt-on-change disabled bit 3-0 unimplemented: read as ? 0 ? note 1: interrupt-on-change also requires that the rabie bit of the intcon register be set. register 6-10: anselb: portb analog select register u-0 u-0 r/w-1 r/w-1 u-0 u-0 u-0 u-0 ? ? ansb5 ansb4 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 ansb<5:4> : analog select between analog or digital function on pins rb<5:4>, respectively 0 = digital i/o. pin is assigned to port or digital special function. 1 = analog input. pin is assigned as analog input (1) . digital input buffer disabled. bit 3-0 unimplemented: read as ? 0 ? note 1: setting a pin to an analog input automatically disables the digital input circuitry. weak pull-ups, if available, are unaffected. the corresponding tris bit must be set to input mode by the user, in order to allow external control of the voltage on the pin.
? 2010-2013 microchip technology inc. ds41430d-page 57 pic16(l)f720/721 6.2.4 pin descriptions and diagrams each portb pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the ssp, i 2 c? or interrupts, refer to the appropriate section in this data sheet. 6.2.4.1 rb4/an10/sdi/sda figure 6-7 shows the diagram for this pin. the rb4 pin is configurable to function as one of the following: ? general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. ? analog input for the a/d ? synchronous serial port input (spi) ?i 2 c data i/o 6.2.4.2 rb5/an11/rx/dt figure 6-8 shows the diagram for this pin. the rb5 pin is configurable to function as one of the following: ? general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. ? analog input for the a/d ? usart asynchronous receive ? usart synchronous receive 6.2.4.3 rb6/sck/scl figure 6-9 shows the diagram for this pin. the rb6 pin is configurable to function as one of the following: ? general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. ? synchronous serial port clock for both spi and i 2 c 6.2.4.4 rb7/tx/ck figure 6-10 shows the diagram for this pin. the rb7 pin is configurable to function as one of the following: ? general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. ? usart asynchronous transmit ? usart synchronous clock figure 6-7: block diagram of rb4 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpub rd wpub rd portb rd portb wr portb wr trisb rd trisb wr iocb rd iocb interrupt-on- to ssp analog (1) input mode rabpu analog (1) input mode change q3 to a/d converter st sspen 0 1 1 0 note 1: ansel determines analog input mode. 0 1 1 0 ssp from ssp
pic16(l)f720/721 ds41430d-page 58 ? 2010-2013 microchip technology inc. figure 6-8: block diag ram of rb5 figure 6-9: block diagram of rb6 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpub rd wpub rd portb rd portb wr portb wr trisb rd trisb wr iocb rd iocb interrupt-on- to ausart rx/dt analog (1) input mode rabpu analog (1) input mode change q3 to a/d converter sync st ausart dt spen note 1: ansel determines analog input mode. 0 1 1 0 0 1 1 0 from ausart i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpub rd wpub rd portb rd portb wr portb wr trisb rd trisb wr iocb rd iocb interrupt-on- to ssp rabpu change q3 sspen st 0 1 1 0 0 1 1 0 from ssp ssp clock
? 2010-2013 microchip technology inc. ds41430d-page 59 pic16(l)f720/721 figure 6-10: blo ck diagram of rb7 i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpub rd wpub rd portb rd portb wr portb wr trisb rd trisb wr iocb rd iocb interrupt-on- rabpu change q3 spen txen ck tx sync ausart ausart 0 1 1 0 0 1 1 0 0 1 1 0 ?1? table 6-2: summary of regist ers associated with portb name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselb ? ? ansb5 ansb4 ? ? ? ? 56 intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ? 56 option_reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 21 portb rb7 rb6 rb5 rb4 ? ? ? ? 55 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 wpub wpub7 wpub6 wpub5 wpub4 ? ? ? ? 55 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portb.
pic16(l)f720/721 ds41430d-page 60 ? 2010-2013 microchip technology inc. 6.3 portc and trisc registers portc is a 8-bit wide, bidirectional port. the corresponding data direction register is trisc ( register 6-12 ). setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). example 6-3 shows how to initialize portc. reading the portc register ( register 6-11 ) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisc register ( register 6-12 ) controls the portc pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisc register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 6-3: initializing portc 6.3.1 anselc register the anselc register ( register 6-13 ) is used to configure the input mode of an i/o pin to analog. setting the appropriate anselc bit high will cause all digital reads on the pin to be read as ? 0 ? and allow analog functions on the pin to operate correctly. the state of the anselc bits has no effect on digital output functions. a pin with tris clear and anselc set will still operate as a digital output, but the input mode will be analog. this can cause unexpected behavior when executing read-modify-write instructions on the affected port. banksel portc ; clrf portc ;init portc banksel trisc ; movlw b?00001100? ;set rc<3:2> as inputs movwf trisc ;and set rc<7:4,1:0> ;as outputs register 6-11: portc: portc register r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u r/w-x/u rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rc<7:0> : portc general purpose i/o pin bits 1 = port pin is > v ih 0 = port pin is < v il
? 2010-2013 microchip technology inc. ds41430d-page 61 pic16(l)f720/721 register 6-12: trisc: po rtc tri-state register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 trisc<7:0>: portc tri-state control bits 1 = portc pin configured as an input (tri-stated) 0 = portc pin configured as an output register 6-13: anselc: analog select register for portc r/w-1 r/w-1 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 ansc7 ansc6 ? ? ansc3 ansc2 ansc1 ansc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 ansc<7:6> : analog select between analog or digital function on pins rb<7:6>, respectively 0 = digital i/o. pin is assigned to port or digital special function. 1 = analog input. pin is assigned as analog input (1) . digital input buffer disabled. bit 5-4 unimplemented : read as ? 0 ? bit 3-0 ansc<3:0> : analog select between analog or digital function on pins rc<3:0>, respectively 0 = digital i/o. pin is assigned to port or digital special function. 1 = analog input. pin is assigned as analog input (1) . digital input buffer disabled. note 1: setting a pin to an analog input automatically disables the digital input circuitry. weak pull-ups, if available, are unaffected. the corresponding tris bit must be set to input mode by the user in order to allow external control of the voltage on the pin.
pic16(l)f720/721 ds41430d-page 62 ? 2010-2013 microchip technology inc. 6.3.2 rc0/an4 figure 6-11 shows the diagram for this pin. the rc0 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d 6.3.3 rc1/an5 figure 6-11 shows the diagram for this pin. the rc1 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d 6.3.4 rc2/an6 figure 6-12 shows the diagram for this pin. the rc2 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d 6.3.5 rc3/an7 figure 6-12 shows the diagram for this pin. the rc3 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d 6.3.6 rc4 figure 6-13 shows the diagram for this pin. the rc4 pin functions as one of the following: ? general purpose i/o 6.3.7 rc5/ccp1 figure 6-14 shows the diagram for this pin. the rc5 pin is configurable to function as one of the following: ? general purpose i/o ? capture, compare or pwm (1 output) 6.3.8 rc6/an8/ss figure 6-15 shows the diagram for this pin. the rc6 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d ?ss input to ssp 6.3.9 rc7/an9/sdo figure 6-16 shows the diagram for this pin. the rc7 pin is configurable to function as one of the following: ? general purpose i/o ? analog input for the a/d ? sdo output of ssp figure 6-11: block diagram of rc0 and rc1 figure 6-12: block diagram of rc2 and rc3 v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc to a/d converter rd portc analog input mode (1) note 1: ansel determines analog input mode. i/o pin v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc rd portc analog input mode (1) note 1: ansel determines analog input mode. i/o pin to a/d converter
? 2010-2013 microchip technology inc. ds41430d-page 63 pic16(l)f720/721 figure 6-13: block diagram of rc4 figure 6-14: block diagram of rc5 figure 6-15: block diagram of rc6 figure 6-16: block diagram of rc7 v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc rd portc i/o pin v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc rd portc ccp1out ccp1out enable 0 1 1 0 i/o pin to c c p1 i n p u t v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc to a/d converter rd portc analog input mode (1) to s s input note 1: ansel determines analog input mode. i/o pin 0 1 1 0 sdo port/sdo v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc to a/d converter rd portc analog input mode (1) note 1: ansel determines analog input mode. i/o pin select
pic16(l)f720/721 ds41430d-page 64 ? 2010-2013 microchip technology inc. table 6-3: summary of registers associated with portc name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselc ansc7 ansc6 ? ? ansc3 ansc2 ansc1 ansc0 61 trisc trisc7 trisc6 trisc5 trisc 4 trisc3 trisc2 trisc1 trisc0 61 portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 60 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portc.
? 2010-2013 microchip technology inc. ds41430d-page 65 pic16(l)f720/721 7.0 oscillator module 7.1 overview the oscillator module has a variety of clock sources and selection features that allow it to be used in a range of applications while maximizing performance and minimizing power consumption. figure 7-1 illustrates a block diagram of the oscillator module. the system can be configured to use an internal calibrated high-frequency oscillator as clock source, with a choice of selectable speeds via software. in addition, the system can also be configured to use an external clock source via the clkin pin. clock source modes are configured by the fosc bits in configuration word 1 (config1). the oscillator module can be configured for one of the following modes of operation. 1. ec ? clkout function on ra4/clkout pin, clkin on ra5/clkin. 2. ec ? i/o function on ra4/clkout pin, clkin on ra5/clkin. 3. intosc ? clkout function on ra4/clkout pin, i/o function on ra5/clkin 4. intoscio ? i/o function on ra4/clkout pin, i/o function on ra5/clkin figure 7-1: simplified pic ? mcu clock source block diagram (cpu and peripherals) clkin ec system clock postscaler mux mux 16 mhz/500 khz 8 mhz/250 khz 4 mhz/125 khz 2 mhz/62.5 khz ircf<1:0> 11 10 01 00 fosc<1:0> (configuration word 1) internal oscillator (osccon register) 500 khz intosc 32x mux 0 1 pll pllen (configuration word 1) mfintosc hfintosc
pic16(l)f720/721 ds41430d-page 66 ? 2010-2013 microchip technology inc. 7.2 clock source modes clock source modes can be classified as external or internal. ? internal clock source (intosc) is contained within the oscillator module and derived from a 500 khz high precision oscillator. the oscillator module has eight selectable output frequencies, with a maximum internal frequency of 16 mhz. ? the external clock mode (ec) relies on an external signal for the clock source. the system clock can be selected between external or internal clock sources via the fosc bits of the configuration word 1. 7.3 internal clock modes the oscillator module has eight output frequencies derived from a 500 khz high precision oscillator. the ircf bits of the osccon register select the postscaler applied to the clock source dividing the frequency by 1, 2, 4 or 8. setting the pllen bit of the configuration word 1 locks the internal clock source to 16 mhz before the postscaler is selected by the ircf bits. the pllen bit must be set or cleared at the time of programming; therefore, only the upper or low four clock source frequencies are selectable in software. the internal oscillator block has one internal oscillator and a dedicated phase-locked loop that are used to generate two internal system clock sources: the 16 mhz high-frequency internal oscillator (hfintosc) and the 500 khz (mfintosc). both can be user- adjusted via software using the osctune register ( register 7-2 ). 7.3.1 intosc and intoscio modes the intosc and intoscio modes configure the internal oscillators as the system clock source when the device is programmed using the oscillator selection or the fosc<1:0> bits in the config1 register. see section 8.0 ?device configuration? for more information. in intosc mode, clkin is available for general purpose i/o. clkout outputs the selected internal oscillator frequency divided by 4. the clkout signal may be used to provide a clock for external circuitry, synchronization, calibration, test or other application requirements. in intoscio mode, clkin and clkout are available for general purpose i/o. 7.3.2 frequency select bits (ircf) the output of the 500 khz mfintosc and 16 mhz hfintosc, with phase-locked loop enabled, con- nect to a postscaler and multiplexer (see figure 7-1 ). the internal oscillator frequency select bits (ircf) of the osccon register select the frequency output of the internal oscillator. depending upon the pllen bit, one of four frequencies of two frequency sets can be selected via software: if pllen = 1 , hfintosc frequency selection is as follows: ?16 mhz ? 8 mhz (default after reset) ?4 mhz ?2 mhz if pllen = 0 , mfintosc frequency selection is as follows: ?500 khz ? 250 khz (default after reset) ?125 khz ?62.5 khz there is no start-up delay before a new frequency selected in the ircf bits takes effect. this is because the old and new frequencies are derived from intosc via the postscaler and multiplexer. start-up delay specifications are located in the table 23-2 in section 23.0 ?electrical specifications? . note: following any reset, the ircf<1:0> bits of the osccon register are set to ? 10 ? and the frequency selection is set to 8 mhz or 250 khz. the user can modify the ircf bits to select a different frequency.
? 2010-2013 microchip technology inc. ds41430d-page 67 pic16(l)f720/721 7.4 oscillator control the oscillator control (osccon) register ( figure 7-1 ) displays the status and allows frequency selection of the internal oscillator (intosc) system clock. the osccon register contains the following bits: ? frequency selection bits (ircf) ? status locked bits (icsl) ? status stable bits (icss) register 7-1: osccon: os cillator control register u-0 u-0 r/w-1 r/w-0 r-q r-q u-0 u-0 ? ? ircf1 ircf0 icsl icss ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown q = value depends on condition bit 7-6 unimplemented: read as ? 0 ? bit 5-4 ircf<1:0>: internal oscillator frequency select bits when pllen = 1 (16 mhz hfintosc) 11 =16mhz 10 =8mhz (default) 01 =4mhz 00 =2mhz when pllen = 0 (500 khz mfintosc) 11 =500khz 10 = 250 khz (default) 01 =125khz 00 =62.5khz bit 3 icsl: internal clock oscillator status locked bit (2% stable) 1 = 16 mhz/500 khz internal oscillator is in lock 0 = 16 mhz/500 khz internal oscillator has not yet locked bit 2 icss: internal clock oscillator status stable bit (0.5% stable) 1 = 16 mhz/500 khz internal oscillator has stabilized to its maximum accuracy 0 = 16 mhz/500 khz internal oscillator has not yet reached its maximum accuracy bit 1-0 unimplemented: read as ? 0 ?
pic16(l)f720/721 ds41430d-page 68 ? 2010-2013 microchip technology inc. 7.5 oscillator tuning the intosc is factory calibrated but can be adjusted in software by writing to the osctune register ( register 7-2 ). the default value of the osctune register is ? 0 ?. the value is a 6-bit two?s complement number. when the osctune register is modified, the intosc frequency will begin shifting to the new frequency. code execution continues during this shift. there is no indication that the shift has occurred. register 7-2: osctune: osci llator tuning register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frequency tuning bits 01 1111 = maximum frequency 01 1110 = ? ? ? 00 0001 = 00 0000 = oscillator module is running at the factory-calibrated frequency. 11 1111 = ? ? ? 10 0000 = minimum frequency
? 2010-2013 microchip technology inc. ds41430d-page 69 pic16(l)f720/721 7.6 external clock modes 7.6.1 ec mode the external clock (ec) mode allows an externally generated logic level as the system clock source. when operating in this mode, an external clock source is connected to the clkin input and the clkout is available for general purpose i/o. figure 7-2 shows the pin connections for ec mode. figure 7-2: exter nal clock (ec) mode operation table 7-2: summary of configuration word wi th clock sources clkin clkout i/o clock from ext. system pic ? mcu table 7-1: summary of registers associated with clock sources name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page osccon ? ? ircf1 ircf0 icsl icss ? ? 67 osctune ? ? tun5 tun4 tun3 tun2 tun1 tun0 68 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by oscillators. name bits bit -/7 bit -/6 bit 13/5 bit 12/4 bit 11/3 bit 10/2 bit 9/1 bit 8/0 register on page config1 13:8 ? ? ? pllen ? ? boren1 boren0 72 7:0 ? cp mclre pwrte wdten ?fosc1fosc0 config2 13:8 ? ? ? ? ? ? ? ? 73 7:0 ? ? ? ? ? ? wrt1 wrt0 legend: ? = unimplemented location, read as ? 0 ?. shaded cells are not used by clock sources.
pic16(l)f720/721 ds41430d-page 70 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 71 pic16(l)f720/721 8.0 device configuration device configuration consists of configuration word 1 and configuration word 2 registers, code protection and device id. 8.1 configuration words there are several configuration word bits that allow different oscillator and memory protection options. these are implemented as configuration word 1 register at 2007h and configuration word 2 register at 2008h. these registers are only accessible during programming.
pic16(l)f720/721 ds41430d-page 72 ? 2010-2013 microchip technology inc. register 8-1: co nfiguration word 1 u-1 r/p-1 u-1 u-1 r/p-1 r/p-1 ? pllen ? ?boren1boren0 bit 13 bit 8 u-1 r/p-1 r/p-1 r/p-1 r/p-1 u-1 r/p-1 r/p-1 ?cp mclre pwrte wdten ?fosc1fosc0 bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 13 unimplemented: read as ? 1 ? bit 12 pllen: intosc pll enable bit 0 = intosc frequency is up to 500 khz (max. mfintosc) 1 = intosc frequency is up to 16 mhz (max. hfintosc) bit 11-10 unimplemented: read as ? 1 ? bit 9-8 boren<1:0>: brown-out reset enable bits (1) 0x = brown-out reset disabled 10 = brown-out reset enabled during operation and disabled in sleep 11 = brown-out reset enabled bit 7 unimplemented: read as ? 1 ? bit 6 cp : flash program memory code protection bit 0 = program memory code protection is enabled 1 = program memory code protection is disabled bit 5 mclre: mclr /v pp pin function select bit 1 =mclr /v pp pin function is mclr ; weak pull-up enabled. 0 =mclr /v pp pin function is digital input; mclr internally disabled; weak pull-up disabled bit 4 pwrte : power-up timer enable bit 0 = pwrt enabled 1 = pwrt disabled bit 3 wdten: watchdog timer enable bit 0 = wdt disabled 1 = wdt enabled bit 2 unimplemented: read as ? 1 ? bit 1-0 fosc<1:0>: oscillator selection bits 11 = ec oscillator: clkout function on clkout pin, and clkin function on clkin pin 10 = ec oscillator: i/o function on clkout pin, and clkin function on clkin pin 01 = intosc oscillator: clkout function on clkout pin, and i/o function on clkin pin 00 = intoscio oscillator: i/o function on clkout pin, and i/o function on clkin pin note 1: fixed voltage reference is automatically enabled whenever the bor is enabled.
? 2010-2013 microchip technology inc. ds41430d-page 73 pic16(l)f720/721 register 8-2: co nfiguration word 2 u-1 u-1 u-1 u-1 u-1 u-1 ? ? ? ? ? ? bit 13 bit 8 u-1 u-1 u-1 reserved u-1 u-1 r/p-1 r/p-1 ? ? ? ? ? ? wrt1 wrt0 bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 13-5 unimplemented : read as ? 1 ? bit 4 reserved: maintain as ? 1 ? bit 3-2 unimplemented : read as ? 1 ? bit 1-0 wrt<1:0>: flash memory self-write protection bits 2 kw flash memory: pic16(l)f720: 11 = write protection off 10 = 000h to 1ffh write-protected, 200h to 7ffh may be modified by pmcon1 control 01 = 000h to 3ffh write-protected, 400h to 7ffh may be modified by pmcon1 control 00 = 000h to 7ffh write-protected, no addresses may be modified by pmcon1 control 4 kw flash memory: pic16(l)f721: 11 = write protection off 10 = 000h to 1ffh write-protected, 200h to fffh may be modified by pmcon1 control 01 = 000h to 7ffh write-protected, 800h to fffh may be modified by pmcon1 control 00 = 000h to fffh write-protected, no addresses may be modified by pmcon1 control
pic16(l)f720/721 ds41430d-page 74 ? 2010-2013 microchip technology inc. 8.2 code protection if the code protection bit(s) have not been programmed, the on-chip program memory can be read out using icsp? for verification purposes. 8.3 user id four memory locations (2000h-2003h) are designated as id locations where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution, but are read- able and writable during program/verify mode. only the least significant 7 bits of the id locations are reported when using mplab ? ide. see the ? pic16(l)f720/721 memory programming specifica- tion? (ds41409) for more information. note: the entire flash program memory will be erased when the code protection is turned off. see the ? pic16(l)f720/721 memory programming specification? (ds41409) for more information.
? 2010-2013 microchip technology inc. ds41430d-page 75 pic16(l)f720/721 9.0 analog-to-digital converter (adc) module the analog-to-digital converter (adc) allows conversion of an analog input signal to a 8-bit binary representation of that signal. this device uses analog inputs, which are multiplexed into a single sample and hold circuit. the output of the sample and hold is connected to the input of the converter. the converter generates a 8-bit binary result via successive approximation and stores the conversion result into the adc result register (adres). figure 9-1 shows the block diagram of the adc. the adc voltage reference, fv ref , is an internally generated supply only. the adc can generate an interrupt upon completion of a conversion. this interrupt can be used to wake-up the device from sleep. figure 9-1: adc block diagram an0 an1 an2 an4 adon go/done chs<3:0> v ss an5 an6 an7 an3 an8 an9 an10 an11 temperature indicator fv ref 0000 0001 0010 0011 0100 0101 0111 0110 1000 1001 1010 1011 1110 1111 8 adc adres v dd
pic16(l)f720/721 ds41430d-page 76 ? 2010-2013 microchip technology inc. 9.1 adc configuration when configuring and using the adc the following functions must be considered: ? port configuration ? channel selection ? adc conversion clock source ? interrupt control 9.1.1 port configuration when converting analog signals, the i/o pin selected as the input channel should be configured for analog by setting the associated tris and ansel bits. refer to section 6.0 ?i/o ports? for more information. 9.1.2 channel selection there are 14 channel selections available: -an<11:0> pins - temperature indicator - fvr (fixed voltage reference) output refer to section 11.0 ?temperature indicator mod- ule? and section 10.0 ?fixed voltage reference? for more information on these channel selections. the chs bits of the adcon0 register determine which channel is connected to the sample and hold circuit. when changing channels, a delay is required before starting the next conversion. refer to section 9.2 ?adc operation? for more information. 9.1.3 conversion clock the source of the conversion clock is software selectable via the adcs bits of the adcon1 register. there are seven possible clock options: ?f osc /2 ?f osc /4 ?f osc /8 ?f osc /16 ?f osc /32 ?f osc /64 ?f rc (dedicated internal oscillator) the time to complete one bit conversion is defined as t ad . one full 8-bit conversion requires 10 t ad periods as shown in figure 9-2 . for correct conversion, the appropriate t ad specification must be met. refer to the a/d conversion requirements in section 23.0 ?electrical specifications? for more information. tab l e 9 - 1 gives examples of appropriate adc clock selections. note: analog voltages on any pin that is defined as a digital input may cause the input buf- fer to conduct excess current. note: unless using the f rc , any changes in the system clock frequency will change the adc clock frequency, which may adversely affect the adc result. table 9-1: adc clock period (t ad ) v s . device operating frequencies adc clock period (t ad ) device frequency (f osc ) adc clock source adcs<2:0> 16 mhz 8 mhz 4 mhz 1 mhz f osc /2 000 125 ns (2) 250 ns (2) 500 ns (2) 2.0 ? s f osc /4 100 250 ns (2) 500 ns (2) 1.0 ? s4.0 ? s f osc /8 001 0.5 ? s (2) 1.0 ? s2.0 ? s8 ? s (5) f osc /16 101 1.0 ? s2.0 ? s4.0 ? s16.0 ? s (5) f osc /32 010 2.0 ? s4.0 ? s8 ? s (5) 32.0 ? s (3) f osc /64 110 4.0 ? s8 ? s (5) 16.0 ? s (5) 64.0 ? s (3) f rc x11 1.0-6.0 ? s (1,4) 1.0-6.0 ? s (1,4) 1.0-6.0 ? s (1,4) 1.0-6.0 ? s (1,4) legend: shaded cells are outside of recommended range. note 1: the f rc source has a typical t ad time of 1.6 ? s for v dd . 2: these values violate the minimum required t ad time. 3: for faster conversion times, the selection of another clock source is recommended. 4: when the device frequency is greater than 1 mhz, the f rc clock source is only recommended if the conversion will be performed during sleep. 5: recommended values for v dd ? 2.0v and temperature -40c to 85c. the 16.0 ? s setting should be avoided for temperature > 85c.
? 2010-2013 microchip technology inc. ds41430d-page 77 pic16(l)f720/721 figure 9-2: analog-to-dig ital conversion t ad cycles 9.1.4 interrupts the adc module allows for the ability to generate an interrupt upon completion of an analog-to-digital conversion. the adc interrupt flag is the adif bit in the pir1 register. the adc interrupt enable is the adie bit in the pie1 register. the adif bit must be cleared in software. this interrupt can be generated while the device is operating or while in sleep. if the device is in sleep, the interrupt will wake-up the device. upon waking from sleep, the next instruction following the sleep instruction is always executed. if the user is attempting to wake-up from sleep and resume in-line code execution, the gie and peie bits of the intcon register must be disabled. if the gie and peie bits of the intcon register are enabled, execution will switch to the interrupt service routine. please refer to section 9.1.4 ?interrupts? for more information. 9.2 adc operation 9.2.1 starting a conversion to enable the adc module, the adon bit of the adcon0 register must be set to a ? 1 ?. setting the go/ done bit of the adcon0 register to a ? 1 ? will start the analog-to-digital conversion. 9.2.2 completion of a conversion when the conversion is complete, the adc module will: ? clear the go/done bit ? set the adif interrupt flag bit ? update the adres register with new conversion result 9.2.3 terminating a conversion if a conversion must be terminated before completion, the go/done bit can be cleared in software. the adres register will be updated with the partially com- plete analog-to-digital conversion sample. incomplete bits will match the last bit converted. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) b7 b6 b5 b4 b3 b2 b1 b0 t cy to t ad conversion starts adres register is loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input t ad 0 note 1: the adif bit is set at the completion of every conversion, regardless of whether or not the adc interrupt is enabled. 2: the adc operates during sleep only when the f rc oscillator is selected. note: the go/done bit should not be set in the same instruction that turns on the adc. refer to section 9.2.6 ?a/d conversion procedure? . note: a device reset forces all registers to their reset state. thus, the adc module is turned off and any pending conversion is terminated.
pic16(l)f720/721 ds41430d-page 78 ? 2010-2013 microchip technology inc. 9.2.4 adc operation during sleep the adc module can operate during sleep. this requires the adc clock source to be set to the f rc option. when the f rc clock source is selected, the adc waits one additional instruction before starting the conversion. this allows the sleep instruction to be executed, which can reduce system noise during the conversion. if the adc interrupt is enabled, the device will wake-up from sleep when the conversion completes. if the adc interrupt is disabled, the adc module is turned off after the conversion completes, although the adon bit remains set. when the adc clock source is something other than f rc , a sleep instruction causes the present conver- sion to be aborted and the adc module is turned off, although the adon bit remains set. 9.2.5 special event trigger the special event trigger of the ccp module allows periodic adc measurements without software inter- vention. when this trigger occurs, the go/done bit is set by hardware and the timer1 counter resets to zero. using the special event trigger does not assure proper adc timing. it is the user?s responsibility to ensure that the adc timing requirements are met. refer to section 15.0 ?capture/compare/pwm (ccp) module? for more information. 9.2.6 a/d conversion procedure this is an example procedure for using the adc to perform an analog-to-digital conversion: 1. configure port: ? disable pin output driver (refer to the tris register) ? configure pin as analog (refer to the ansel register) 2. configure the adc module: ? select adc conversion clock ? select adc input channel ? turn on adc module 3. configure adc interrupt (optional): ? clear adc interrupt flag ? enable adc interrupt ? enable peripheral interrupt ? enable global interrupt (1) 4. wait the required acquisition time (2) . 5. start conversion by setting the go/done bit. 6. wait for adc conversion to complete by one of the following: ? polling the go/done bit ? waiting for the adc interrupt (interrupts enabled) 7. read adc result. 8. clear the adc interrupt flag (required if interrupt is enabled). example 9-1: a/d conversion note 1: the global interrupt can be disabled if the user is attempting to wake-up from sleep and resume in-line code execution. 2: refer to section 9.3 ?a/d acquisition requirements? . ;this code block configures the adc ;for polling, vdd reference, frc clock ;and an0 input. ; ;conversion start & polling for completion ; are included. ; banksel adcon1 ; movlw b?01110000? ;adc frc clock, ;v dd reference movwf adcon1 ; banksel trisa ; bsf trisa,0 ;set ra0 to input banksel ansela ; bsf ansela,0 ;set ra0 to analog banksel adcon0 ; movlw b?00000001?;an0, on movwf adcon0 ; call sampletime ;acquisiton delay bsf adcon0,go ;start conversion btfsc adcon0,go ;is conversion done? goto $-1 ;no, test again banksel adres ; movf adres,w ;read result movwf result ;store in gpr space
? 2010-2013 microchip technology inc. ds41430d-page 79 pic16(l)f720/721 9.2.7 adc register definitions the following registers are used to control the operation of the adc. register 9-1: adcon0: a/ d control register 0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-2 chs<3:0>: analog channel select bits 0000 =an0 0001 =an1 0010 =an2 0011 =an3 0100 =an4 0101 =an5 0110 =an6 0111 =an7 1000 =an8 1001 =an9 1010 =an10 1011 =an11 1110 = temperature indicator (1) 1111 = fixed voltage reference (fv ref ) (2) bit 1 go/done : a/d conversion status bit 1 = a/d conversion cycle in progress. setting this bit starts an a/d conversion cycle. this bit is automatically cleared by hardware when the a/d conversion has completed. 0 = a/d conversion completed/not in progress bit 0 adon: adc enable bit 1 = adc is enabled 0 = adc is disabled and consumes no operating current note 1: see section 11.0 ?temperature indicator module? for more information. 2: see section 10.0 ?fixed voltage reference? for more information.
pic16(l)f720/721 ds41430d-page 80 ? 2010-2013 microchip technology inc. register 9-2: adcon1: a/ d control register 1 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? adcs2 adcs1 adcs0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 adcs<2:0>: a/d conversion clock select bits 000 =f osc /2 001 =f osc /8 010 =f osc /32 011 =f rc (clock supplied from a dedicated rc oscillator) 100 =f osc /4 101 =f osc /16 110 =f osc /64 111 =f rc (clock supplied from a dedicated rc oscillator) bit 3-0 unimplemented: read as ? 0 ? register 9-3: adres: adc result register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres7 adres6 adres5 adres4 adres3 adres2 adres1 adres0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adres<7:0> : adc result register bits 8-bit conversion result.
? 2010-2013 microchip technology inc. ds41430d-page 81 pic16(l)f720/721 9.3 a/d acquisition requirements for the adc to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 9-3 . the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), refer to figure 9-3 . the maximum recommended impedance for analog sources is 10 k ? . as the source impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (or changed), an a/d acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 9-1 may be used. this equation assumes that 1/2 lsb error is used (256 steps for the adc). the 1/2 lsb error is the maximum error allowed for the adc to meet its specified resolution. it is noted that if the device is operated at or below 2.0v v dd with the frc clock selected for the adc and if the analog input changes by more than one or two lsbs from the previous conversion, then the use of at least 16 ? s t acq time is recommended. equation 9-1: acquisition time example t acq amplifier settling time hold capacitor charging time temperature coefficient ++ = t amp t c t c off ++ = 2s t c temperature - 25c ?? 0.05s/c ?? ?? ++ = t c c hold r ic r ss r s ++ ?? ln(1/511) ? = 20pf 1k ? 7k ? 10k ? ++ ?? ? ln(0.001957) = 2.25 = s t acq 2s 2.25 s 50c- 25c ?? 0.05s/c ?? ?? ++ = 5.5 s = v applied 1e tc ? rc --------- ? ?? ?? ?? v applied 1 1 2 n1 + ?? 1 ? -------------------------- ? ?? ?? = v applied 1 1 2 n1 + ?? 1 ? -------------------------- ? ?? ?? v chold = v applied 1e t c ? rc --------- - ? ?? ?? ?? v chold = ;[1] v chold charged to within 1/2 lsb ;[2] v chold charge response to v applied ;combining [1] and [2] the value for t c can be approximated with the following equations: solving for t c : therefore: temperature 50c and external impedance of 10k ? 5.0v v dd = assumptions: note: where n = number of bits of the adc. note: t coff is zero for temperatures below 25 degrees c.
pic16(l)f720/721 ds41430d-page 82 ? 2010-2013 microchip technology inc. figure 9-3: analog input model figure 9-4: adc transfer function note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k ? . this is required to meet the pin leakage specification. c pin va rs anx 5 pf v dd v t ? 0.6v v t ? 0.6v i leakage (1) r ic ? 1k sampling switch ss rss c hold = 20 pf v ss 6v sampling switch, typical 4v 2v 510 (k ? ) v dd legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance various junctions note 1: refer to section 23.0 ?electrical specifications? . r ss = resistance of sampling switch 15 20 ffh feh adc output code fdh fch 04h 03h 02h 01h 00h full-scale fbh 1 lsb ideal v ss zero-scale transition v ref transition 1 lsb ideal full-scale range analog input voltage
? 2010-2013 microchip technology inc. ds41430d-page 83 pic16(l)f720/721 table 9-2: summary of associated adc registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page adcon0 ? ? chs3 chs2 chs1 chs0 go/ done adon 79 adcon1 ? adcs2 adcs1 adcs0 ? ? ? ? 80 ansela ? ? ansa5 ansa4 ? ansa2 ansa1 ansa0 47 anselb ? ? ansb5 ansb4 ? ? ? ? 56 anselc ansc7 ansc6 ? ? ansc3 ansc2 ansc1 ansc0 61 adres adc result register 80 fvrcon fvrrdy fvren tsen tsrng ? ? adfvr1 adfvr0 86 intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 trisa ? ? trisa5 trisa4 ? trisa2 trisa1 trisa0 46 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?, q = value depends on condition. shaded cells are not used for adc module.
pic16(l)f720/721 ds41430d-page 84 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 85 pic16(l)f720/721 10.0 fixed voltage reference this device contains an internal voltage regulator. to provide a reference for the regulator, a fixed voltage reference is provided. this fixed voltage is also user accessible via an a/d converter channel. user level fixed voltage functions are controlled by the fvrcon register, which is shown in register 10-1 . figure 10-1: voltage reference block diagram table 10-1: peripherals requiring the fixed voltage reference (fvr) peripheral conditions description hfintosc fosc = 1 ec on clkin pin. bor boren<1:0> = 11 bor always enabled. boren<1:0> = 10 and borfs = 1 bor disabled in sleep mode, bor fast start enabled. boren<1:0> = 01 and borfs = 1 bor under software control, bor fast start enabled. ivr all pic16f720/721 devices, when vregpm1 = 1 and not in sleep the device runs off of the power-save mode regulator when in sleep mode. fvr (to adc module) x1 x2 x4 + - 1.024v fixed reference fvren fvrrdy 2 adfvr<1:0> any peripheral requiring the fixed reference (see table 10-1 )
pic16(l)f720/721 ds41430d-page 86 ? 2010-2013 microchip technology inc. register 10-1: fvrcon: fixed voltage reference register r-q r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r/w-0 fvrrdy fvren tsen tsrng ? ? adfvr1 adfvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown q = value depends on condition bit 7 fvrrdy (1) : fixed voltage reference ready flag bit 0 = fixed voltage reference output is not active or stable 1 = fixed voltage reference output is ready for use bit 6 fvren: fixed voltage reference enable bit 0 = fixed voltage reference is disabled 1 = fixed voltage reference is enabled bit 5 tsen: temperature indicator enable bit (3) 0 = temperature indicator is disabled 1 = temperature indicator is enabled bit 4 tsrng: temperature indicator range selection bit (3) 1 =v out = v dd - 4vt (high range) 0 =v out = v dd - 2vt (low range) bit 3-2 unimplemented: read as ? 0 ? bit 1-0 adfvr<1:0>: a/d converter fixed voltage reference selection bits 00 = a/d converter fixed voltage reference peripheral output is off 01 = a/d converter fixed voltage reference peripheral output is 1x (1.024v) 10 = a/d converter fixed voltage reference peripheral output is 2x (2.048v) (2) 11 = a/d converter fixed voltage reference peripheral output is 4x (4.096v) (2) note 1: fvrrdy is always ? 1 ? for the pic16f720/721 devices. 2: fixed voltage reference output cannot exceed v dd . 3: see section 11.0 ?temperature indicator module? for additional information. table 10-2: summary of associated fixed voltage reference registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page fvrcon fvrrdy fvren tsen tsrng ? ? adfvr1 adfvr0 86 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?, q = value depends on condition. shaded cells are not used for fixed voltage reference.
? 2010-2013 microchip technology inc. ds41430d-page 87 pic16(l)f720/721 11.0 temperature indicator module this family of devices is equipped with a temperature circuit designed to measure the operating temperature of the silicon die. the circuit?s range of operating temperature falls between -40c and +85c. the output is a voltage that is proportional to the device temperature. the output of the temperature indicator is internally connected to the device adc. the circuit may be used as a temperature threshold detector or a more accurate temperature indicator, depending on the level of calibration performed. a one- point calibration allows the circuit to indicate a temperature closely surrounding that point. a two-point calibration allows the circuit to sense the entire range of temperature more accurately. reference application note an1333, ? use and calibration of the internal temperature indicator ? (ds01333) for more details regarding the calibration process. 11.1 circuit operation figure 11-1 shows a simplified block diagram of the temperature circuit. the proportional voltage output is achieved by measuring the forward voltage drop across multiple silicon junctions. equation 11-1 describes the output characteristics of the temperature indicator. equation 11-1: v out ranges the temperature sense circuit is integrated with the fixed voltage reference (fvr) module. see section 10.0 ?fixed voltage reference? for more information. the circuit is enabled by setting the tsen bit of the fvrcon register. when disabled, the circuit draws no current. the circuit operates in either high or low range. the high range, selected by setting the tsrng bit of the fvrcon register, provides a wider output voltage. this provides more resolution over the temperature range, but may be less consistent from part to part. this range requires a higher bias voltage to operate and thus, a higher v dd is needed. the low range is selected by clearing the tsrng bit of the fvrcon register. the low range generates a lower voltage drop and thus, a lower bias voltage is needed to operate the circuit. the low range is provided for low voltage operation. figure 11-1: temperature circuit diagram 11.2 minimum operating v dd vs. minimum sensing temperature when the temperature circuit is operated in low range, the device may be operated at any operating voltage that is within specifications. when the temperature circuit is operated in high range, the device operating voltage, v dd , must be high enough to ensure that the temperature circuit is correctly biased. table 11-1 shows the recommended minimum v dd vs. range setting. table 11-1: recommended v dd vs. range 11.3 temperature output the output of the circuit is measured using the internal analog-to-digital converter. channel 14 is reserved for the temperature circuit output. refer to section 9.0 ?analog-to-digital converter (adc) module? for detailed information. high range: v out = v dd - 4v t low range: v out = v dd - 2v t min. v dd , tsrng = 1 min. v dd , tsrng = 0 3.6v 1.8v note: every time the adc mux is changed to the temperature indicator output selection (chs bit in the adccon0 register), wait 500 usec for the sampling capacitor to fully charge before sampling the tempera- ture indicator output. tsen tsrng v dd to a d c v out
pic16(l)f720/721 ds41430d-page 88 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 89 pic16(l)f720/721 12.0 timer0 module the timer0 module is an 8-bit timer/counter with the following features: ? 8-bit timer/counter register (tmr0) ? 8-bit prescaler (shared with watchdog timer) ? programmable internal or external clock source ? programmable external clock edge selection ? interrupt on overflow ? tmr0 can be used to gate timer1 figure 12-1 is a block diagram of the timer0 module. 12.1 timer0 operation the timer0 module can be used as either an 8-bit timer or an 8-bit counter. 12.1.1 8-bit timer mode the timer0 module will increment every instruction cycle, if used without a prescaler. 8-bit timer mode is selected by clearing the t0cs bit of the option_reg register. when tmr0 is written, the increment is inhibited for two instruction cycles immediately following the write. 12.1.2 8-bit counter mode in 8-bit counter mode, the timer0 module will increment on every rising or falling edge of the t0cki pin. 8-bit counter mode using the t0cki pin is selected by setting the t0cs bit in the option_reg register to ? 1 ?. the rising or falling transition of the incrementing edge for either input source is determined by the t0se bit in the option_reg register. figure 12-1: block di agram of the timer0/wdt prescaler note: the value written to the tmr0 register can be adjusted, in order to account for the two instruction cycle delay when tmr0 is written. t0cki t0se tmr0 wdt time-out ps<2:0> wdten data bus set flag bit t0if on overflow t0cs 0 1 0 1 0 1 8 8 8-bit prescaler 0 1 f osc /4 psa psa psa s ync 2 t cy overflow to timer1 divide by 512 tmr1ge t1gss = 11 low-power wdt
pic16(l)f720/721 ds41430d-page 90 ? 2010-2013 microchip technology inc. 12.1.3 software programmable prescaler a single software programmable prescaler is available for use with either timer0 or the watchdog timer (wdt), but not both simultaneously. the prescaler assignment is controlled by the psa bit of the option_reg register. to assign the prescaler to timer0, the psa bit must be cleared to a ? 0 ?. there are eight prescaler options for the timer0 mod- ule ranging from 1:2 to 1:256. the prescale values are selectable via the ps<2:0> bits of the option_reg register. in order to have a 1:1 prescaler value for the timer0 module, the prescaler must be assigned to the wdt module. the prescaler is not readable or writable. when assigned to the timer0 module, all instructions writing to the tmr0 register will clear the prescaler. 12.1.4 timer0 interrupt timer0 will generate an interrupt when the tmr0 register overflows from ffh to 00h. the tmr0if interrupt flag bit of the intcon register is set every time the tmr0 register overflows, regardless of whether or not the timer0 interrupt is enabled. the tmr0if bit can only be cleared in software. the timer0 interrupt enable is the tmr0ie bit of the intcon register. 12.1.5 8-bit counter mode synchronization when in 8-bit counter mode, the incrementing edge on the t0cki pin must be synchronized to the instruction clock. synchronization can be accomplished by sampling the prescaler output on the q2 and q4 cycles of the instruction clock. the high and low periods of the external clocking source must meet the timing requirements as shown in section 23.0 ?electrical specifications? . note: when the prescaler is assigned to wdt, a clrwdt instruction will clear the prescaler along with the wdt. note: the timer0 interrupt cannot wake the processor from sleep since the timer is frozen during sleep.
? 2010-2013 microchip technology inc. ds41430d-page 91 pic16(l)f720/721 12.2 option register register 12-1: option_reg: option register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rabpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rabpu : porta or portb pull-up enable bit 1 = porta or portb pull-ups are disabled 0 = porta or portb pull-ups are enabled by individual port latch values bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of int pin 0 = interrupt on falling edge of int pin bit 5 t0cs: tmr0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (f osc /4) bit 4 t0se: tmr0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt r ate table 12-1: summary of registers associated with timer0 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 option_reg rabpu intedg t0cs t0se psa ps2 ps1 ps0 21 tmr0 timer0 module register 89 trisa ? ? trisa5 trisa4 ? trisa2 trisa1 trisa0 46 legend: ? = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the timer0 module.
pic16(l)f720/721 ds41430d-page 92 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 93 pic16(l)f720/721 13.0 timer1 module with gate control the timer1 module is a 16-bit timer/counter with the following features: ? 16-bit timer/counter register pair (tmr1h:tmr1l) ? programmable internal or external clock source ? 3-bit prescaler ? synchronous or asynchronous operation ? multiple timer1 gate (count enable) sources ? interrupt on overflow ? wake-up on overflow (external clock, asynchronous mode only) ? time base for the capture/compare function ? special event trigger (with ccp) ? selectable gate source polarity ? gate toggle mode ? gate single-pulse mode ? gate value status ? gate event interrupt figure 13-1 is a block diagram of the timer1 module. figure 13-1: timer1 block diagram tmr1h tmr1l t1sync t1ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit tmr1if on overflow tmr1 (2) tmr1on note 1: st buffer is high speed type when using t1cki. 2: timer1 register increments on rising edge. 3: synchronize does not operate while in sleep. t1g f osc /4 internal clock t1cki tmr1cs<1:0> (1) synchronize (3) det sleep input tmr1ge 0 1 00 01 10 11 from timer0 from timer2 t1gpol d q ck q 0 1 t1gval single pulse acq. control t1gspm t1ggo/done t1gss<1:0> 10 11 00 01 f osc internal clock reserved from wdt overflow match pr2 overflow r d en q q1 rd t1gcon data bus det interrupt tmr1gif set t1clk f osc /2 internal clock d en q t1g_in tmr1on t1gtm
pic16(l)f720/721 ds41430d-page 94 ? 2010-2013 microchip technology inc. 13.1 timer1 operation the timer1 module is a 16-bit incrementing counter which is accessed through the tmr1h:tmr1l register pair. writes to tmr1h or tmr1l directly update the counter. when used with an internal clock source, the module is a timer and increments on every instruction cycle. when used with an external clock source, the module can be used as either a timer or counter and increments on every selected edge of the external source. timer1 is enabled by configuring the tmr1on and tmr1ge bits in the t1con and t1gcon registers, respectively. table 13-1 displays the timer1 enable selections. 13.2 clock source selection the tmr1cs<1:0> bits of the t1con register are used to select the clock source for timer1. table 13-2 displays the clock source selections. 13.2.1 internal clock source when the internal clock source is selected the tmr1h:tmr1l register pair will increment on multiples of f osc as determined by the timer1 prescaler. 13.2.2 external clock source when the external clock source is selected, the timer1 module may work as a timer or a counter. when enabled to count, timer1 is incremented on the rising edge of the external clock input t1cki. table 13-2: clock source selections table 13-1: timer1 enable selections tmr1on tmr1ge timer1 operation 00 off 01 off 10 always on 11 count enabled note: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge after any one or more of the following conditions: ?timer1 enabled after por reset ?write to tmr1h or tmr1l ?timer1 is disabled ?timer1 is disabled (tmr1on = 0 ) when t1cki is high then timer1 is enabled (tmr1on= 1 ) when t1cki is low. tmr1cs<1:0> clock source 01 system clock (f osc ) 00 instruction clock (f osc /4) 10 external clocking on t1cki pin 11 reserved
? 2010-2013 microchip technology inc. ds41430d-page 95 pic16(l)f720/721 13.3 timer1 prescaler timer1 has four prescaler options allowing 1, 2, 4 or 8 divisions of the clock input. the t1ckps bits of the t1con register control the prescale counter. the prescale counter is not directly readable or writable; however, the prescaler counter is cleared upon a write to tmr1h or tmr1l. 13.4 timer1 operation in asynchronous counter mode if control bit t1sync of the t1con register is set, the external clock input is not synchronized. the timer increments asynchronously to the internal phase clocks. if external clock source is selected then the timer will continue to run during sleep and can generate an interrupt on overflow, which will wake-up the processor. however, special precautions in software are needed to read/write the timer (see section 13.4.1 ?reading and writing timer1 in asynchronous counter mode? ). 13.4.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l while the timer is running from an external asynchronous clock will ensure a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write contention may occur by writing to the timer registers, while the register is incrementing. this may produce an unpredictable value in the tmr1h:tmr1l register pair. 13.5 timer1 gate timer1 can be configured to count freely or the count can be enabled and disabled using timer1 gate circuitry. this is also referred to as timer1 gate count enable. timer1 gate can also be driven by multiple selectable sources. 13.5.1 timer1 gate count enable the timer1 gate is enabled by setting the tmr1ge bit of the t1gcon register. the polarity of the timer1 gate is configured using the t1gpol bit of the t1gcon register. when timer1 gate (t1g ) input is active, timer1 will increment on the rising edge of the timer1 clock source. when timer1 gate input is inactive, no incrementing will occur and timer1 will hold the current count. see figure 13-3 for timing details. 13.5.2 timer1 gate source selection the timer1 gate source can be selected from one of four different sources. source selection is controlled by the t1gss bits of the t1gcon register. the polarity for each available source is also selectable. polarity selection is controlled by the t1gpol bit of the t1gcon register. note: when switching from synchronous to asynchronous operation, it is possible to skip an increment. when switching from asynchronous to synchronous operation, it is possible to produce an additional increment. table 13-3: timer1 gate enable selections t1clk t1gpol t1g timer1 operation ? 00 counts ? 01 holds count ? 10 holds count ? 11 counts table 13-4: timer1 gate sources t1gss timer1 gate source 00 timer1 gate pin 01 overflow of timer0 (tmr0 increments from ffh to 00h) 10 timer2 match pr2 (tmr2 increments to match pr2) 11 count enabled by wdt overflow (watchdog time-out interval expired)
pic16(l)f720/721 ds41430d-page 96 ? 2010-2013 microchip technology inc. 13.5.2.1 t1g pin gate operation the t1g pin is one source for timer1 gate control. it can be used to supply an external source to the timer1 gate circuitry. 13.5.2.2 timer0 overflow gate operation when timer0 increments from ffh to 00h, a low-to- high pulse will automatically be generated and internally supplied to the timer1 gate circuitry. 13.5.2.3 timer2 match gate operation the tmr2 register will increment until it matches the value in the pr2 register. on the very next increment cycle, tmr2 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be generated and internally supplied to the timer1 gate circuitry. 13.5.2.4 watchdog overflow gate operation the watchdog timer oscillator, prescaler and counter will be automatically turned on when tmr1ge = 1 and t1gss selects the wdt as a gate source for timer1 (t1gss = 11 ). tmr1on does not factor into the oscil- lator, prescaler and counter enable. see table 13-5 . the psa and ps bits of the option_reg register still control what time-out interval is selected. changing the prescaler during operation may result in a spurious capture. enabling the watchdog timer oscillator does not automatically enable a watchdog reset or wake-up from sleep upon counter overflow. as the gate signal coming from the wdt counter will generate different pulse widths depending on if the wdt is enabled, when the clrwdt instruction is executed, and so on, toggle mode must be used. a specific sequence is required to put the device into the correct state to capture the next wdt counter interval. note: when using the wdt as a gate source for timer1, operations that clear the watchdog timer ( clrwdt , sleep instructions) will affect the time interval being measured. this includes waking from sleep. all other interrupts that might wake the device from sleep should be disabled to prevent them from disturbing the measurement period. table 13-5: wdt/timer1 gate interaction wdten tmr1ge = 1 and t1gss = 11 wdt oscillator enable wdt reset wake-up wdt available for t1g source 1 n yyy n 1 y yyy y 0 y ynn y 0 n nnn n
? 2010-2013 microchip technology inc. ds41430d-page 97 pic16(l)f720/721 13.5.3 timer1 gate toggle mode when timer1 gate toggle mode is enabled, it is possible to measure the full-cycle length of a timer1 gate signal, as opposed to the duration of a single level pulse. the timer1 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. see figure 13-4 for timing details. timer1 gate toggle mode is enabled by setting the t1gtm bit of the t1gcon register. when the t1gtm bit is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. 13.5.4 timer1 gate single-pulse mode when timer1 gate single-pulse mode is enabled, it is possible to capture a single pulse gate event. timer1 gate single-pulse mode is first enabled by setting the t1gspm bit in the t1gcon register. next, the t1ggo/done bit in the t1gcon register must be set. the timer1 will be fully enabled on the next incrementing edge. on the next trailing edge of the pulse, the t1ggo/done bit will automatically be cleared. no other gate events will be allowed to increment timer1 until the t1ggo/done bit is once again set in software. clearing the t1gspm bit of the t1gcon register will also clear the t1ggo/done bit. see figure 13-5 for timing details. enabling the toggle mode and the single-pulse mode simultaneously will permit both sections to work together. this allows the cycle times on the timer1 gate source to be measured. see figure 13-6 for timing details. 13.5.5 timer1 gate value status when timer1 gate value status is utilized, it is possible to read the most current level of the gate control value. the value is stored in the t1gval bit in the t1gcon register. the t1gval bit is valid even when the timer1 gate is not enabled (tmr1ge bit is cleared). 13.5.6 timer1 gate event interrupt when timer1 gate event interrupt is enabled, it is possible to generate an interrupt upon the completion of a gate event. when the falling edge of t1gval occurs, the tmr1gif flag bit in the pir1 register will be set. if the tmr1gie bit in the pie1 register is set, then an interrupt will be recognized. the tmr1gif flag bit operates even when the timer1 gate is not enabled (tmr1ge bit is cleared). note: enabling toggle mode at the same time as changing the gate polarity may result in indeterminate operation.
pic16(l)f720/721 ds41430d-page 98 ? 2010-2013 microchip technology inc. 13.6 timer1 interrupt the timer1 register pair (tmr1h:tmr1l) increments to ffffh and rolls over to 0000h. when timer1 rolls over, the timer1 interrupt flag bit of the pir1 register is set. to enable the interrupt on rollover, you must set these bits: ? tmr1on bit of the t1con register ? tmr1ie bit of the pie1 register ? peie bit of the intcon register ? gie bit of the intcon register the interrupt is cleared by clearing the tmr1if bit in the interrupt service routine. 13.7 timer1 operation during sleep timer1 can only operate during sleep when setup in asynchronous counter mode. in this mode, the clock source can be used to increment the counter. to set up the timer to wake the device: ? tmr1on bit of the t1con register must be set ? tmr1ie bit of the pie1 register must be set ? peie bit of the intcon register must be set ? t1sync bit of the t1con register must be set ? tmr1cs bits of the t1con register must be configured ? tmr1ge bit of the t1gcon register must be configured the device will wake-up on an overflow and execute the next instructions. if the gie bit of the intcon register is set, the device will call the interrupt service routine (0004h). 13.8 ccp capture/compare time base the ccp module uses the tmr1h:tmr1l register pair as the time base when operating in capture or compare mode. in capture mode, the value in the tmr1h:tmr1l register pair is copied into the ccpr1h:ccpr1l register pair on a configured event. in compare mode, an event is triggered when the value ccpr1h:ccpr1l register pair matches the value in the tmr1h:tmr1l register pair. this event can be a special event trigger. for more information, see section 15.0 ?capture/ compare/pwm (ccp) module? . 13.9 ccp special event trigger when the ccp is configured to trigger a special event, the trigger will clear the tmr1h:tmr1l register pair. this special event does not cause a timer1 interrupt. the ccp module may still be configured to generate a ccp interrupt. in this mode of operation, the ccpr1h:ccpr1l register pair becomes the period register for timer1. timer1 should be synchronized to the f osc /4 to utilize the special event trigger. asynchronous operation of timer1 can cause a special event trigger to be missed. in the event that a write to tmr1h or tmr1l coincides with a special event trigger from the ccp, the write will take precedence. for more information, see section 9.2.5 ?special event trigger? . figure 13-2: timer1 incrementing edge note: the tmr1h:tmr1l register pair and the tmr1if bit should be cleared before enabling interrupts. t1cki = 1 when tmr1 enabled t1cki = 0 when tmr1 enabled note 1: arrows indicate counter increments. 2: in counter mode, a falling edge must be registered by the count er prior to the first incrementing rising edge of the clock.
? 2010-2013 microchip technology inc. ds41430d-page 99 pic16(l)f720/721 figure 13-3: timer1 gate count enable mode figure 13-4: timer1 gate toggle mode tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4 tmr1ge t1gpol t1gtm t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
pic16(l)f720/721 ds41430d-page 100 ? 2010-2013 microchip technology inc. figure 13-5: timer1 gate single-pulse mode tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 t1gspm t1ggo/ done set by software cleared by hardware on falling edge of t1gval set by hardware on falling edge of t1gval cleared by software cleared by software tmr1gif counting enabled on rising edge of t1g
? 2010-2013 microchip technology inc. ds41430d-page 101 pic16(l)f720/721 figure 13-6: timer1 gate single-pulse and toggle combined mode tmr1ge t1gpol t1g_in t1cki t1gval timer1 nn + 1 n + 2 t1gspm t1ggo/ done set by software cleared by hardware on falling edge of t1gval set by hardware on falling edge of t1gval cleared by software cleared by software tmr1gif t1gtm counting enabled on rising edge of t1g n + 4 n + 3
pic16(l)f720/721 ds41430d-page 102 ? 2010-2013 microchip technology inc. 13.10 timer1 control register the timer1 control register (t1con), shown in register 13-1 , is used to control timer1 and select the various features of the timer1 module. register 13-1: t1con: ti mer1 control register r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 r/w-0 tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 ? t1sync ?tmr1on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmr1cs<1:0>: timer1 clock source select bits 11 = reserved 10 = timer1 clock source is pin or oscillator. external clock from t1cki pin (on the rising edge) 01 = timer1 clock source is system clock (f osc ) 00 = timer1 clock source is instruction clock (f osc /4) bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 unimplemented: read as ? 0 ? bit 2 t 1sync : timer1 external clock input synchronization control bit tmr1cs<1:0> = 1x 1 = do not synchronize external clock input 0 = synchronize external clock input with system clock (f osc ) tmr1cs<1:0> = 0x this bit is ignored. timer1 uses the internal clock when tmr1cs<1:0> = 1x . bit 1 unimplemented: read as ? 0 ? bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 clears timer1 gate flip-flop
? 2010-2013 microchip technology inc. ds41430d-page 103 pic16(l)f720/721 13.11 timer1 gate control register the timer1 gate control register (t1gcon), shown in register 13-2 , is used to control timer1 gate. register 13-2: t1gcon: timer1 gate control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr1ge t1gpol t1gtm t1gspm t1ggo/ done t1gval t1gss1 t1gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr1ge: timer1 gate enable bit if tmr1on = 0 : this bit is ignored if tmr1on = 1 : 1 = timer1 counting is controlled by the timer1 gate function 0 = timer1 counts regardless of timer1 gate function bit 6 t1gpol: timer1 gate polarity bit 1 = timer1 gate is active-high (timer1 counts when gate is high) 0 = timer1 gate is active-low (timer1 counts when gate is low) bit 5 t1gtm: timer1 gate toggle mode bit 1 = timer1 gate toggle mode is enabled. 0 = timer1 gate toggle mode is disabled and toggle flip-flop is cleared timer1 gate flip-flop toggles on every rising edge. bit 4 t1gspm: timer1 gate single pulse mode bit 1 = timer1 gate single-pulse mode is enabled and is controlling timer1 gate 0 = timer1 gate single-pulse mode is disabled bit 3 t1ggo/done : timer1 gate single-pulse acquisition status bit 1 = timer1 gate single-pulse acquisition is ready, waiting for an edge 0 = timer1 gate single-pulse acquisition has completed or has not been started this bit is automatically cleared when t1gspm is cleared. bit 2 t1gval: timer1 gate current state bit indicates the current state of the timer1 gate that could be provided to tmr1h:tmr1l. unaffected by timer1 gate enable (tmr1ge). bit 1-0 t1gss<1:0>: timer1 gate source select bits 00 = timer1 gate pin 01 = timer0 overflow output 10 = tmr2 match pr2 output 11 = watchdog timer scaler overflow watchdog timer oscillator is turned on if tmr1ge = 1 , regardless of the state of tmr1on
pic16(l)f720/721 ds41430d-page 104 ? 2010-2013 microchip technology inc. table 13-6: summary of registers associated with timer1 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselb ? ? ansb5 ansb4 ? ? ? ? 56 ccp1con ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 107 intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 portb rb7 rb6 rb5 rb4 ? ? ? ? 55 tmr1h holding register for the most significant byte of the 16-bit tmr1 register 98 tmr1l holding register for the least significant byte of the 16-bit tmr1 register 98 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 ? t1sync ?tmr1on 102 t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ done t1gval t1gss1 t1gss0 103 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module.
? 2010-2013 microchip technology inc. ds41430d-page 105 pic16(l)f720/721 14.0 timer2 module the timer2 module is an 8-bit timer with the following features: ? 8-bit timer register (tmr2) ? 8-bit period register (pr2) ? interrupt on tmr2 match with pr2 ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) see figure 14-1 for a block diagram of timer2. 14.1 timer2 operation the clock input to the timer2 module is the system instruction clock (f osc /4). the clock is fed into the timer2 prescaler, which has prescale options of 1:1, 1:4 or 1:16. the output of the prescaler is then used to increment the tmr2 register. the values of tmr2 and pr2 are constantly compared to determine when they match. tmr2 will increment from 00h until it matches the value in pr2. when a match occurs, two things happen: ? tmr2 is reset to 00h on the next increment cycle. ? the timer2 postscaler is incremented. the match output of the timer2/pr2 comparator is then fed into the timer2 postscaler. the postscaler has postscale options of 1:1 to 1:16 inclusive. the output of the timer2 postscaler is used to set the tmr2if interrupt flag bit in the pir1 register. the tmr2 and pr2 registers are both fully readable and writable. on any reset, the tmr2 register is set to 00h and the pr2 register is set to ffh. timer2 is turned on by setting the tmr2on bit in the t2con register to a ? 1 ?. timer2 is turned off by clearing the tmr2on bit to a ? 0 ?. the timer2 prescaler is controlled by the t2ckps bits in the t2con register. the timer2 postscaler is controlled by the toutps bits in the t2con register. the prescaler and postscaler counters are cleared when: ? a write to tmr2 occurs. ? a write to t2con occurs. ? any device reset occurs (power-on reset, mclr reset, watchdog timer reset, or brown-out reset). figure 14-1: timer2 block diagram note: tmr2 is not cleared when t2con is written. comparator tmr2 sets flag tmr2 output reset postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if toutps<3:0> t2ckps<1:0>
pic16(l)f720/721 ds41430d-page 106 ? 2010-2013 microchip technology inc. 14.2 timer2 control register register 14-1: t2con: ti mer2 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 toutps<3:0>: timer2 output postscaler select bits 0000 =1:1 postscaler 0001 =1:2 postscaler 0010 =1:3 postscaler 0011 =1:4 postscaler 0100 =1:5 postscaler 0101 =1:6 postscaler 0110 =1:7 postscaler 0111 =1:8 postscaler 1000 =1:9 postscaler 1001 = 1:10 postscaler 1010 = 1:11 postscaler 1011 = 1:12 postscaler 1100 = 1:13 postscaler 1101 = 1:14 postscaler 1110 = 1:15 postscaler 1111 = 1:16 postscaler bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 table 14-1: summary of registers associated with timer2 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 pr2 timer2 module period register 105 tmr2 timer2 module register 105 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 106 legend: x = unknown, u = unchanged, - = unimplemented read as ? 0 ?. shaded cells are not used for timer2 module.
? 2010-2013 microchip technology inc. ds41430d-page 107 pic16(l)f720/721 15.0 capture/compare/pwm (ccp) module the capture/compare/pwm module is a peripheral which allows the user to time and control different events. in capture mode, the peripheral allows the timing of the duration of an event. the compare mode allows the user to trigger an external event when a predetermined amount of time has expired. the pwm mode can generate a pulse-width modulated signal of varying frequency and duty cycle. the timer resources used by the module are shown in table 15-1 . additional information on ccp modules is available in the application note an594, ?using the ccp modules? (ds00594). table 15-1: ccp mode ? timer resources required ccp mode timer resource capture timer1 compare timer1 pwm timer2 register 15-1: ccp1con: ccp1 control register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dc1:b1 : pwm duty cycle least significant bits capture mode : unused compare mode: unused pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr1l. bit 3-0 ccp1m<3:0>: ccp mode select bits 0000 = capture/compare/pwm off (resets ccp module) 0001 = unused (reserved) 0010 = compare mode, toggle output on match (ccp1if bit of the pirx register is set) 0011 = unused (reserved) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit of the pir1 register is set) 1001 = compare mode, clear output on match (ccp1if bit of the pir1 register is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set of the pirx register, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit of the pir1register is set, tmr1 is reset and a/d conversion is started if the adc module is enabled. ccp1 pin is unaffected.) 11xx = pwm mode.
pic16(l)f720/721 ds41430d-page 108 ? 2010-2013 microchip technology inc. 15.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin ccp1. an event is defined as one of the following and is configured by the ccp1m<3:0> bits of the ccp1con register: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge when a capture is made, the interrupt request flag bit ccp1if of the pir1 register is set. the interrupt flag must be cleared in software. if another capture occurs before the value in the ccpr1h, ccpr1l register pair is read, the old captured value is overwritten by the new captured value (refer to figure 15-1 ). 15.1.1 ccp1 pin configuration in capture mode, the ccp1 pin should be configured as an input by setting the associated tris control bit. figure 15-1: capture mode operation block diagram 15.1.2 timer1 mode selection timer1 must be running in timer mode or synchronized counter mode for the ccp module to use the capture feature. in asynchronous counter mode or when timer1 is clocked at f osc , the capture operation may not work. 15.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccp1ie interrupt enable bit of the pie1 register clear to avoid false interrupts. additionally, the user should clear the ccp1if interrupt flag bit of the pir1 register following any change in operating mode 15.1.4 ccp prescaler there are four prescaler settings specified by the ccp1m<3:0> bits of the ccp1con register. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. any reset will clear the prescaler counter. switching from one capture prescaler to another does not clear the prescaler and may generate a false interrupt. to avoid this unexpected operation, turn the module off by clearing the ccp1con register before changing the prescaler (refer to example 15-1 ). example 15-1: changing between capture prescalers 15.1.5 capture during sleep capture mode depends upon the timer1 module for proper operation. there are two options for driving the timer1 module in capture mode. it can be driven by the instruction clock (f osc /4), or by an external clock source. if timer1 is clocked by f osc /4, then timer1 will not increment during sleep. when the device wakes from sleep, timer1 will continue from its previous state. if timer1 is clocked by an external clock source, then capture mode will operate as defined in section 15.1 ?capture mode? . note: if the ccp1 pin is configured as an output, a write to the port can cause a capture condition. note: clocking timer1 from the system clock (f osc ) should not be used in capture mode. in order for capture mode to recognize the trigger event on the ccp1 pin, timer1 must be clocked from the instruction clock (f osc /4) or from an external clock source. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1 register) capture enable ccp1con<3:0> prescaler ? 1, 4, 16 and edge detect ccp1 system clock (f osc ) banksel ccp1con ;set bank bits to point ;to ccp1con clrf ccp1con ;turn ccp module off movlw new_capt_ps ;load the w reg with ; the new prescaler ; move value and ccp on movwf ccp1con ;load ccp1con with this ; value
? 2010-2013 microchip technology inc. ds41430d-page 109 pic16(l)f720/721 table 15-2: summary of registers associated with capture name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselb ? ? ansb5 ansb4 ? ? ? ? 56 ccp1con ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 107 ccpr1l capture/compare/pwm register low byte ? ccpr1h capture/compare/pwm register high byte ? intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 ? t1sync ?tmr1on 102 t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ done t1gval t1gss1 t1gss0 103 tmr1l holding register for the least significant byte of the 16-bit tmr1 register 98 tmr1h holding register for the most significant byte of the 16-bit tmr1 register 98 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 legend: - = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the capture.
pic16(l)f720/721 ds41430d-page 110 ? 2010-2013 microchip technology inc. 15.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the ccp1 module may: ? toggle the ccp1 output ? set the ccp1 output ? clear the ccp1 output ? generate a special event trigger ? generate a software interrupt the action on the pin is based on the value of the ccp1m<3:0> control bits of the ccp1con register. all compare modes can generate an interrupt. figure 15-2: compare mode operation block diagram 15.2.1 ccp1 pin configuration the user must configure the ccp1 pin as an output by clearing the associated tris bit. 15.2.2 timer1 mode selection in compare mode, timer1 must be running in either timer mode or synchronized counter mode. the compare operation may not work in asynchronous counter mode. 15.2.3 software interrupt mode when software interrupt mode is chosen (ccp1m<3:0> = 1010 ), the ccp1if bit in the pir1 register is set and the ccp1 module does not assert control of the ccp1 pin (refer to the ccp1con register). 15.2.4 special event trigger when special event trigger mode is chosen (ccp1m<3:0> = 1011 ), the ccp1 module does the following: ? resets timer1 ? starts an adc conversion if adc is enabled the ccp1 module does not assert control of the ccp1 pin in this mode (refer to the ccp1con register). the special event trigger output of the ccp occurs immediately upon a match between the tmr1h, tmr1l register pair and the ccpr1h, ccpr1l register pair. the tmr1h, tmr1l register pair is not reset until the next rising edge of the timer1 clock. this allows the ccpr1h, ccpr1l register pair to effectively provide a 16-bit programmable period register for timer1. 15.2.5 compare during sleep the compare mode is dependent upon the system clock (f osc ) for proper operation. since f osc is shut down during sleep mode, the compare mode will not function properly during sleep. note: clearing the ccp1con register will force the ccp1 compare output latch to the default low level. this is not the port i/o data latch. ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic special event trigger set ccp1if interrupt flag (pir1) match tris ccp1con<3:0> mode select output enable special event trigger will: ? clear tmr1h and tmr1l registers. ? not set interrupt flag bit tmr1if of the pir1 register. ? set the go/done bit to start the adc conversion. ccp1 4 note: clocking timer1 from the system clock (f osc ) should not be used in compare mode. for the compare operation of the tmr1 register to the ccpr1 register to occur, timer1 must be clocked from the instruction clock (f osc /4) or from an external clock source. note 1: the special event trigger from the ccp module does not set interrupt flag bit tmr1if of the pir1 register. 2: removing the match condition by changing the contents of the ccpr1h and ccpr1l register pair, between the clock edge that generates the special event trigger and the clock edge that generates the timer1 reset, will preclude the reset from occurring.
? 2010-2013 microchip technology inc. ds41430d-page 111 pic16(l)f720/721 table 15-3: summary of regist ers associated with compare name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page adcon0 ? ? chs3 chs2 chs1 chs0 go/ done adon 79 anselb ? ? ansb5 ansb4 ? ? ? ? 56 ccp1con ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 107 ccpr1l capture/compare/pwm register low byte ? ccpr1h capture/compare/pwm register high byte ? intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 ? t1sync ?tmr1on 102 t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ done t1gval t1gss1 t1gss0 103 tmr1l holding register for the least significant byte of the 16-bit tmr1 register 98 tmr1h holding register for the most significant byte of the 16-bit tmr1 register 98 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 legend: - = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the compare.
pic16(l)f720/721 ds41430d-page 112 ? 2010-2013 microchip technology inc. 15.3 pwm mode the pwm mode generates a pulse-width modulated signal on the ccp1 pin. the duty cycle, period and resolution are determined by the following registers: ?pr2 ?t2con ? ccpr1l ? ccp1con in pulse-width modulation (pwm) mode, the ccp module produces up to a 10-bit resolution pwm output on the ccp1 pin. figure 15-3 shows a simplified block diagram of pwm operation. figure 15-4 shows a typical waveform of the pwm signal. for a step-by-step procedure on how to set up the ccp module for pwm operation, refer to section 15.3.8 ?setup for pwm operation? . figure 15-3: simplified pwm block diagram the pwm output ( figure 15-4 ) has a time base (period) and a time that the output stays high (duty cycle). figure 15-4: ccp pwm output 15.3.1 ccpx pin configuration in pwm mode, the ccp1 pin is multiplexed with the port data latch. the user must configure the ccp1 pin as an output by clearing the associated tris bit. ccpr1l ccpr1h (2) (slave) comparator tmr2 pr2 (1) rq s duty cycle registers ccp1con<5:4> clear timer2, toggle ccp1 pin and latch duty cycle note 1: the 8-bit timer tmr2 register is concatenated with the 2-bit internal system clock (f osc ), or two bits of the prescaler, to create the 10-bit time base. 2: in pwm mode, ccpr1h is a read-only register. tris ccp1 comparator note: clearing the ccp1con register will relinquish ccp1 control of the ccp1 pin. period pulse width tmr2 = 0 tmr2 = ccpr1l:ccp1con<5:4> tmr2 = pr2
? 2010-2013 microchip technology inc. ds41430d-page 113 pic16(l)f720/721 15.3.2 pwm period the pwm period is specified by the pr2 register of timer2. the pwm period can be calculated using the formula of equation 15-1 . equation 15-1: pwm period when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ? tmr2 is cleared ? the ccp1 pin is set. (exception: if the pwm duty cycle = 0%, the pin will not be set.) ? the pwm duty cycle is latched from ccpr1l into ccpr1h. 15.3.3 pwm duty cycle the pwm duty cycle is specified by writing a 10-bit value to multiple registers: ccpr1l register and dc1 and b1 bits of the ccp1con register. the ccpr1l contains the eight msbs and the dc1 and b1 bits of the ccp1con register contain the two lsbs. ccpr1l and dc1 and b1 bits of the ccp1con register can be written to at any time. the duty cycle value is not latched into ccpr1h until after the period completes (i.e., a match between pr2 and tmr2 registers occurs). while using the pwm, the ccpr1h register is read-only. equation 15-2 is used to calculate the pwm pulse width. equation 15-3 is used to calculate the pwm duty cycle ratio. equation 15-2: pulse width equation 15-3: duty cycle ratio the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitchless pwm operation. the 8-bit timer tmr2 register is concatenated with either the 2-bit internal system clock (f osc ), or two bits of the prescaler, to create the 10-bit time base. the system clock is used if the timer2 prescaler is set to 1:1. when the 10-bit time base matches the ccpr1h and 2-bit latch, then the ccp1 pin is cleared (refer to figure 15-3 ). note: the timer2 postscaler (refer to section 14.1 ?timer2 operation? ) is not used in the determination of the pwm frequency. pwm period pr2 ?? 1 + ?? 4t osc ? ? ? = (tmr2 prescale value) note: t osc = 1/f osc pulse width ccpr1l:ccp1con<5:4> ?? ? = t osc ? (tmr2 prescale value) note: t osc = 1/f osc duty cycle ratio ccpr1l:ccp1con<5:4> ?? 4pr2 1 + ?? ----------------------------------------------------------------------- =
pic16(l)f720/721 ds41430d-page 114 ? 2010-2013 microchip technology inc. 15.3.4 pwm resolution the resolution determines the number of available duty cycles for a given period. for example, a 10-bit resolution will result in 1024 discrete duty cycles, whereas an 8-bit resolution will result in 256 discrete duty cycles. the maximum pwm resolution is 10 bits when pr2 is 255. the resolution is a function of the pr2 register value as shown by equation 15-4 . equation 15-4: pwm resolution 15.3.5 operation in sleep mode in sleep mode, the tmr2 register will not increment and the state of the module will not change. if the ccp1 pin is driving a value, it will continue to drive that value. when the device wakes up, tmr2 will continue from its previous state. 15.3.6 changes in system clock frequency the pwm frequency is derived from the system clock frequency (f osc ). any changes in the system clock frequency will result in changes to the pwm frequency. refer to section 7.0 ?oscillator module? for additional details. 15.3.7 effects of reset any reset will force all ports to input mode and the ccp registers to their reset states. 15.3.8 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. disable the pwm pin (ccp1) output driver(s) by setting the associated tris bit(s). 2. load the pr2 register with the pwm period value. 3. configure the ccp module for the pwm mode by loading the ccp1con register with the appropriate values. 4. load the ccpr1l register and the dcxbx bits of the ccp1con register, with the pwm duty cycle value. 5. configure and start timer2: ? clear the tmr2if interrupt flag bit of the pir1 register. see note below. ? configure the t2ckps bits of the t2con register with the timer2 prescale value. ? enable timer2 by setting the tmr2on bit of the t2con register. 6. enable pwm output pin: ? wait until timer2 overflows, tmr2if bit of the pir1 register is set. see note below. ? enable the pwm pin (ccp1) output driver(s) by clearing the associated tris bit(s). note: if the pulse width value is greater than the period the assigned pwm pin(s) will remain unchanged. resolution 4pr2 1 + ?? ?? log 2 ?? log ----------------------------------------- - bits = table 15-4: example pwm frequencies and resolutions (f osc = 16 mhz) pwm frequency 977 hz 3.91 khz 15.625 khz 62.50 khz 125.0 khz 250.0 khz timer prescale (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xff 0xff 0xff 0x3f 0x1f 0x0f maximum resolution (bits) 10 10 10 8 7 6 table 15-5: example pwm frequencies and resolutions (f osc = 8 mhz) pwm frequency 1.22 khz 4.90 khz 19.61 khz 76.92 khz 153.85 khz 200.0 khz timer prescale (1, 4, 16) 16 4 1 1 1 1 pr2 value 0x65 0x65 0x65 0x19 0x0c 0x09 maximum resolution (bits) 8 8 8 6 5 5 note: in order to send a complete duty cycle and period on the first pwm output, the above steps must be included in the setup sequence. if it is not critical to start with a complete pwm signal on the first output, then step 6 may be ignored.
? 2010-2013 microchip technology inc. ds41430d-page 115 pic16(l)f720/721 table 15-6: summary of registers associated with pwm name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselb ? ? ansb5 ansb4 ? ? ? ? 56 ccp1con ? ? dc1 b1 ccp1m3 ccp1m2 ccp1m1 ccp1m0 107 ccpr1l capture/compare/pwm register low byte ? ccpr1h capture/compare/pwm register high byte ? pr2 timer2 module period register 105 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 106 tmr2 timer2 module register 105 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 legend: - = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the pwm.
pic16(l)f720/721 ds41430d-page 116 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 117 pic16(l)f720/721 16.0 addressable universal synchronous asynchronous receiver transmitter (ausart) the addressable universal synchronous asynchronous receiver transmitter (ausart) module is a serial i/o communications peripheral. it contains all the clock generators, shift registers and data buffers necessary to perform an input or output serial data transfer independent of device program execution. the ausart, also known as a serial communications interface (sci), can be configured as a full-duplex asynchronous system or half-duplex synchronous system. full-duplex mode is useful for communications with peripheral systems, such as crt terminals and personal computers. half-duplex synchronous mode is intended for communications with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms or other microcontrollers. these devices typically do not have internal clocks for baud rate generation and require the external clock signal provided by a master synchronous device. the ausart module includes the following capabilities: ? full-duplex asynchronous transmit and receive ? two-character input buffer ? one-character output buffer ? programmable 8-bit or 9-bit character length ? address detection in 9-bit mode ? input buffer overrun error detection ? received character framing error detection ? half-duplex synchronous master ? half-duplex synchronous slave ? sleep operation block diagrams of the ausart transmitter and receiver are shown in figure 16-1 and figure 16-2 . figure 16-1: ausart transmit block diagram txif txie interrupt txen tx9d msb lsb data bus txreg register transmit shift register (tsr) (8) 0 tx9 trmt spen tx/ck pin buffer and control 8 spbrg f osc n n + 1 multiplier x4 x16 x64 sync 100 brgh x10 baud rate generator ???
pic16(l)f720/721 ds41430d-page 118 ? 2010-2013 microchip technology inc. figure 16-2: ausart recei ve block diagram the operation of the ausart module is controlled through two registers: ? transmit status and control (txsta) ? receive status and control (rcsta) these registers are detailed in register 16-1 and register 16-2 , respectively. rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 stop start (8) 7 1 0 rx9 ? ? ? spbrg f osc n n + 1 multiplier x4 x16 x64 sync 100 brgh x10 baud rate generator
? 2010-2013 microchip technology inc. ds41430d-page 119 pic16(l)f720/721 16.1 ausart asynchronous mode the ausart transmits and receives data using the standard non-return-to-zero (nrz) format. nrz is implemented with two levels: a v oh mark state which represents a ? 1 ? data bit, and a v ol space state which represents a ? 0 ? data bit. nrz refers to the fact that consecutively transmitted data bits of the same value stay at the output level of that bit without returning to a neutral level between each bit transmission. an nrz transmission port idles in the mark state. each character transmission consists of one start bit followed by eight or nine data bits and is always terminated by one or more stop bits. the start bit is always a space and the stop bits are always marks. the most common data format is eight bits. each transmitted bit persists for a period of 1/(baud rate). an on-chip dedicated 8-bit baud rate generator is used to derive standard baud rate frequencies from the system oscillator. refer to table 16-5 for examples of baud rate configurations. the ausart transmits and receives the lsb first. the ausart?s transmitter and receiver are functionally independent, but share the same data format and baud rate. parity is not supported by the hardware, but can be implemented in software and stored as the ninth data bit. 16.1.1 ausart asynchronous transmitter the ausart transmitter block diagram is shown in figure 16-1 . the heart of the transmitter is the serial transmit shift register (tsr), which is not directly accessible by software. the tsr obtains its data from the transmit buffer, which is the txreg register. 16.1.1.1 enabling the transmitter the ausart transmitter is enabled for asynchronous operations by configuring the following three control bits: ?txen = 1 ? sync = 0 ? spen = 1 all other ausart control bits are assumed to be in their default state. setting the txen bit of the txsta register enables the transmitter circuitry of the ausart. clearing the sync bit of the txsta register configures the ausart for asynchronous operation. setting the spen bit of the rcsta register enables the ausart and automatically configures the tx/ck i/o pin as an output. 16.1.1.2 transmitting data a transmission is initiated by writing a character to the txreg register. if this is the first character, or the previous character has been completely flushed from the tsr, the data in the txreg is immediately transferred to the tsr register. if the tsr still contains all or part of a previous character, the new character data is held in the txreg until the stop bit of the previous character has been transmitted. the pending character in the txreg is then transferred to the tsr in one t cy immediately following the stop bit transmission. the transmission of the start bit, data bits and stop bit sequence commences immediately following the transfer of the data to the tsr from the txreg. 16.1.1.3 transmit interrupt flag the txif interrupt flag bit of the pir1 register is set whenever the ausart transmitter is enabled and no character is being held for transmission in the txreg. in other words, the txif bit is only clear when the tsr is busy with a character and a new character has been queued for transmission in the txreg. the txif flag bit is not cleared immediately upon writing txreg. txif becomes valid in the second instruction cycle following the write execution. polling txif immediately following the txreg write will return invalid results. the txif bit is read-only, it cannot be set or cleared by software. the txif interrupt can be enabled by setting the txie interrupt enable bit of the pie1 register. however, the txif flag bit will be set whenever the txreg is empty, regardless of the state of txie enable bit. to use interrupts when transmitting data, set the txie bit only when there is more data to send. clear the txie interrupt enable bit upon writing the last character of the transmission to the txreg. note 1: when the spen bit is set the rx/dt i/o pin is automatically configured as an input, regardless of the state of the correspond- ing tris bit and whether or not the aus- art receiver is enabled. the rx/dt pin data can be read via a normal port read but port latch data output is precluded. 2: the txif transmitter interrupt flag is set when the txen enable bit is set.
pic16(l)f720/721 ds41430d-page 120 ? 2010-2013 microchip technology inc. 16.1.1.4 tsr status the trmt bit of the txsta register indicates the status of the tsr register. this is a read-only bit. the trmt bit is set when the tsr register is empty and is cleared when a character is transferred to the tsr register from the txreg. the trmt bit remains clear until all bits have been shifted out of the tsr register. no interrupt logic is tied to this bit, so the user has to poll this bit to determine the tsr status. 16.1.1.5 transmitting 9-bit characters the ausart supports 9-bit character transmissions. when the tx9 bit of the txsta register is set, the ausart will shift nine bits out for each character trans- mitted. the tx9d bit of the txsta register is the ninth, and most significant, data bit. when transmitting 9-bit data, the tx9d data bit must be written before writing the eight least significant bits into the txreg. all nine bits of data will be transferred to the tsr shift register immediately after the txreg is written. a special 9-bit address mode is available for use with multiple receivers. refer to section 16.1.2.7 ?address detection? for more information on the address mode. 16.1.1.6 asynchronous transmission setup: 1. initialize the spbrg register and the brgh bit to achieve the desired baud rate (refer to section 16.2 ?ausart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if 9-bit transmission is desired, set the tx9 control bit. a set ninth data bit will indicate that the eight least significant data bits are an address when the receiver is set for address detection. 4. enable the transmission by setting the txen control bit. this will cause the txif interrupt bit to be set. 5. if interrupts are desired, set the txie interrupt enable bit of the pie1 register. an interrupt will occur immediately provided that the gie and peie bits of the intcon register are also set. 6. if 9-bit transmission is selected, the ninth bit should be loaded into the tx9d data bit. 7. load 8-bit data into the txreg register. this will start the transmission. figure 16-3: asynchronous transmission note: the tsr register is not mapped in data memory, so it is not available to the user. word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) tx/ck pin txif bit (transmit buffer empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy
? 2010-2013 microchip technology inc. ds41430d-page 121 pic16(l)f720/721 figure 16-4: asynchronous transmiss ion (back-to-back) 16.1.2 ausart asynchronous receiver the asynchronous mode is typically used in rs-232 systems. the receiver block diagram is shown in figure 16-2 . the data is received on the rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at 16 times the baud rate, whereas the serial receive shift register (rsr) operates at the bit rate. when all eight or nine bits of the character have been shifted in, they are immediately transferred to a two character first-in first-out (fifo) memory. the fifo buffering allows reception of two complete characters and the start of a third character before software must start servicing the ausart receiver. the fifo and rsr registers are not directly accessible by software. access to the received data is via the rcreg register. 16.1.2.1 enabling the receiver the ausart receiver is enabled for asynchronous operation by configuring the following three control bits: ? cren = 1 ? sync = 0 ? spen = 1 all other ausart control bits are assumed to be in their default state. setting the cren bit of the rcsta register enables the receiver circuitry of the ausart. clearing the sync bit of the txsta register configures the ausart for asynchronous operation. setting the spen bit of the rcsta register enables the ausart and automatically configures the rx/dt i/o pin as an input. transmit shift reg. write to txreg brg output (shift clock) tx/ck pin trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy txif bit (transmit buffer empty flag) table 16-1: registers associated with asynchronous transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 127 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txreg ausart transmit data register ? txsta csrc tx9 txen sync ? brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for asynchronous transmission. note: when the spen bit is set, the tx/ck i/o pin is automatically configured as an output, regardless of the state of the corresponding tris bit and whether or not the ausart transmitter is enabled. the port latch is disconnected from the output driver so it is not possible to use the tx/ck pin as a general purpose output.
pic16(l)f720/721 ds41430d-page 122 ? 2010-2013 microchip technology inc. 16.1.2.2 receiving data the receiver data recovery circuit initiates character reception on the falling edge of the first bit. the first bit, also known as the start bit, is always a zero. the data recovery circuit counts one-half bit time to the center of the start bit and verifies that the bit is still a zero. if it is not a zero then the data recovery circuit aborts character reception, without generating an error, and resumes looking for the falling edge of the start bit. if the start bit zero verification succeeds then the data recovery circuit counts a full bit time to the center of the next bit. the bit is then sampled by a majority detect circuit and the resulting ? 0 ? or ? 1 ? is shifted into the rsr. this repeats until all data bits have been sampled and shifted into the rsr. one final bit time is measured and the level sampled. this is the stop bit, which is always a ? 1 ?. if the data recovery circuit samples a ? 0 ? in the stop bit position then a framing error is set for this character, otherwise the framing error is cleared for this character. refer to section 16.1.2.4 ?receive framing error? for more information on framing errors. immediately after all data bits and the stop bit have been received, the character in the rsr is transferred to the ausart receive fifo and the rcif interrupt flag bit of the pir1 register is set. the top character in the fifo is transferred out of the fifo by reading the rcreg register. 16.1.2.3 receive interrupts the rcif interrupt flag bit of the pir1 register is set whenever the ausart receiver is enabled and there is an unread character in the receive fifo. the rcif interrupt flag bit is read-only, it cannot be set or cleared by software. rcif interrupts are enabled by setting all of the following bits: ? rcie interrupt enable bit of the pie1 register ? peie, peripheral interrupt enable bit of the intcon register ? gie, global interrupt enable bit of the intcon register the rcif interrupt flag bit of the pir1 register will be set when there is an unread character in the fifo, regardless of the state of interrupt enable bits. 16.1.2.4 receive framing error each character in the receive fifo buffer has a corresponding framing error status bit. a framing error indicates that a stop bit was not seen at the expected time. the framing error status is accessed via the ferr bit of the rcsta register. the ferr bit represents the status of the top unread character in the receive fifo. therefore, the ferr bit must be read before reading the rcreg. the ferr bit is read-only and only applies to the top unread character in the receive fifo. a framing error (ferr = 1 ) does not preclude reception of additional characters. it is not necessary to clear the ferr bit. reading the next character from the fifo buffer will advance the fifo to the next character and the next corresponding framing error. the ferr bit can be forced clear by clearing the spen bit of the rcsta register which resets the ausart. clearing the cren bit of the rcsta register does not affect the ferr bit. a framing error by itself does not generate an interrupt. 16.1.2.5 receive overrun error the receive fifo buffer can hold two characters. an overrun error will be generated if a third character, in its entirety, is received before the fifo is accessed. when this happens the oerr bit of the rcsta register is set. the characters already in the fifo buffer can be read but no additional characters will be received until the error is cleared. the error must be cleared by either clearing the cren bit of the rcsta register or by setting the ausart by clearing the spen bit of the rcsta register. 16.1.2.6 receiving 9-bit characters the ausart supports 9-bit character reception. when the rx9 bit of the rcsta register is set, the ausart will shift 9 bits into the rsr for each character received. the rx9d bit of the rcsta register is the ninth and most significant data bit of the top unread character in the receive fifo. when reading 9-bit data from the receive fifo buffer, the rx9d data bit must be read before reading the 8 least significant bits from the rcreg. note: if the receive fifo is overrun, no additional characters will be received until the overrun condition is cleared. refer to section 16.1.2.5 ?receive overrun error? for more information on overrun errors. note: if all receive characters in the receive fifo have framing errors, repeated reads of the rcreg will not clear the ferr bit.
? 2010-2013 microchip technology inc. ds41430d-page 123 pic16(l)f720/721 16.1.2.7 address detection a special address detection mode is available for use when multiple receivers share the same transmission line, such as in rs-485 systems. address detection is enabled by setting the adden bit of the rcsta register. address detection requires 9-bit character reception. when address detection is enabled, only characters with the ninth data bit set will be transferred to the receive fifo buffer, thereby setting the rcif interrupt bit of the pir1 register. all other characters will be ignored. upon receiving an address character, user software determines if the address matches its own. upon address match, user software must disable address detection by clearing the adden bit before the next stop bit occurs. when user software detects the end of the message, determined by the message protocol used, software places the receiver back into the address detection mode by setting the adden bit. 16.1.2.8 asynchronous reception setup: 1. initialize the spbrg register and the brgh bit to achieve the desired baud rate (refer to section 16.2 ?ausart baud rate generator (brg)? ). 2. enable the serial port by setting the spen bit. the sync bit must be clear for asynchronous operation. 3. if interrupts are desired, set the rcie bit of the pie1 register and the gie and peie bits of the intcon register. 4. if 9-bit reception is desired, set the rx9 bit. 5. enable reception by setting the cren bit. 6. the rcif interrupt flag bit of the pir1 register will be set when a character is transferred from the rsr to the receive buffer. an interrupt will be generated if the rcie bit of the pie1 register was also set. 7. read the rcsta register to get the error flags and, if 9-bit data reception is enabled, the ninth data bit. 8. get the received 8 least significant data bits from the receive buffer by reading the rcreg register. 9. if an overrun occurred, clear the oerr flag by clearing the cren receiver enable bit. 16.1.2.9 9-bit address detection mode setup this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrg register and the brgh bit to achieve the desired baud rate (refer to section 16.2 ?ausart baud rate generator (brg)? ). 2. enable the serial port by setting the spen bit. the sync bit must be clear for asynchronous operation. 3. if interrupts are desired, set the rcie bit of the pie1 register and the gie and peie bits of the intcon register. 4. enable 9-bit reception by setting the rx9 bit. 5. enable address detection by setting the adden bit. 6. enable reception by setting the cren bit. 7. the rcif interrupt flag bit of the pir1 register will be set when a character with the ninth bit set is transferred from the rsr to the receive buffer. an interrupt will be generated if the rcie inter- rupt enable bit of the pie1 register was also set. 8. read the rcsta register to get the error flags. the ninth data bit will always be set. 9. get the received 8 least significant data bits from the receive buffer by reading the rcreg register. software determines if this is the device?s address. 10. if an overrun occurred, clear the oerr flag by clearing the cren receiver enable bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and generate interrupts.
pic16(l)f720/721 ds41430d-page 124 ? 2010-2013 microchip technology inc. figure 16-5: asynchronous reception start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx/dt pin reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word, causing the oerr (overrun) bit to be set. table 16-2: registers associated with asynchronous reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcreg ausart receive data register 123 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 127 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txsta csrc tx9 txen sync ?brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for asynchronous reception.
? 2010-2013 microchip technology inc. ds41430d-page 125 pic16(l)f720/721 register 16-1: txsta: transmit status and control register r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen (1) sync ? brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode : don?t care synchronous mode : 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync: ausart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented: read as ? 0 ? bit 2 brgh: high baud rate select bit asynchronous mode : 1 = high speed 0 = low speed synchronous mode: unused in this mode bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: ninth bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in synchronous mode.
pic16(l)f720/721 ds41430d-page 126 ? 2010-2013 microchip technology inc. register 16-2: rcsta: receive status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit (1) 1 = serial port enabled (configures rx/dt and tx/ck pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care synchronous mode ? master : 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care bit 4 cren: continuous receive enable bit asynchronous mode : 1 = enables receiver 0 = disables receiver synchronous mode : 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enable interrupt and load the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 8-bit (rx9 = 0 ) : don?t care synchronous mode : must be set to ? 0 ? bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: ninth bit of received data this can be address/data bit or a parity bit and must be calculated by user firmware. note 1: the ausart module automatically changes the pin from tri-state to drive as needed. configure trisx = 1 .
? 2010-2013 microchip technology inc. ds41430d-page 127 pic16(l)f720/721 16.2 ausart baud rate generator (brg) the baud rate generator (brg) is an 8-bit timer that is dedicated to the support of both the asynchronous and synchronous ausart operation. the spbrg register determines the period of the free running baud rate timer. in asynchronous mode the multiplier of the baud rate period is determined by the brgh bit of the txsta register. in synchronous mode, the brgh bit is ignored. table 16-3 contains the formulas for determining the baud rate. example 16-1 provides a sample calculation for determining the baud rate and baud rate error. typical baud rates and error values for various asynchronous modes have been computed for your convenience and are shown in table 16-5 . it may be advantageous to use the high baud rate (brgh = 1 ), to reduce the baud rate error. writing a new value to the spbrg register causes the brg timer to be reset (or cleared). this ensures that the brg does not wait for a timer overflow before outputting the new baud rate. example 16-1: calculating baud rate error for a device with f osc of 16 mhz, desired baud rate of 9600, and asynchronous mode with sync = 0 and brgh = 0 (as seen in table 16-5 ): solving for spbrg: spbrg f osc 64 desired baud rate ?? --------------------------------------------------------- ?? ?? 1 ? = desired baud rate f osc 64 spbrg 1 + ?? --------------------------------------- = 16000000 64 9600 ?? ------------------------ ?? ?? 1 ? = 25.042 ?? 25 == actual baud rate 16000000 64 25 1 + ?? -------------------------- - = 9615 = error actual baud rate desired baud rate ? desired baud rate ------------------------------------------------------------------------------------------------- - ?? ?? 100 = 9615 9600 ? 9600 ----------------------------- - ?? ?? 100 0.16% == % table 16-3: baud rate formulas configuration bits ausart mode baud rate formula sync brgh 00 asynchronous f osc /[64 (n+1)] 01 asynchronous f osc /[16 (n+1)] 1x synchronous f osc /[4 (n+1)] legend: x = don?t care, n = value of spbrg register table 16-4: registers associated with the baud rate generator name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page rcsta spen rx9 sren cren adden ferr oerr rx9d 126 spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 127 txsta csrc tx9 txen sync ?brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for the baud rate generator.
pic16(l)f720/721 ds41430d-page 128 ? 2010-2013 microchip technology inc. table 16-5: baud rates for asynchronous modes baud rate sync = 0 , brgh = 0 f osc = 16.0000 mhz f osc = 11.0592 mhz f osc = 8.000 mhz f osc = 4.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 ?? ? ? ? ? ? ? ? 300 0.16 207 1200 1201 0.08 207 1200 0.00 143 1202 0.16 103 1202 0.16 51 2400 2403 0.16 103 2400 0.00 71 2404 0.16 51 2404 0.16 25 9600 9615 0.16 25 9600 0.00 17 9615 0.16 12 ? ? ? 10417 10416 -0.01 23 10165 -2.42 16 10417 0.00 11 10417 0.00 5 19.2k 19.23k 0.16 12 19.20k 0.00 8 ? ? ? ? ? ? 57.6k ? ? ? 57.60k 0.00 2 ? ? ? ? ? ? 115.2k ? ? ? ? ? ? ? ? ? ? ? ? baud rate sync = 0 , brgh = 0 f osc = 3.6864 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300 0.00 191 300 0.16 51 1200 1200 0.00 47 1202 0.16 12 2400 2400 0.00 23 ? ? ? 9600 9600 0.00 5 ? ? ? 10417 ? ? ? ? ? ? 19.2k 19.20k 0.00 2 ? ? ? 57.6k 57.60k 0.00 0 ? ? ? 115.2k ? ? ? ? ? ?
? 2010-2013 microchip technology inc. ds41430d-page 129 pic16(l)f720/721 baud rate sync = 0 , brgh = 1 f osc = 16.0000 mhz f osc = 11.0592 mhz f osc = 8.000 mhz f osc = 4.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 ?? ? ?? ? ?? ? ?? ? 1200 ? ? ? ? ? ? ? ? ? 1202 0.16 207 2400 ? ? ? ?? ? 2404 0.16 207 2404 0.16 103 9600 9615 0.16 103 9600 0.00 71 9615 0.16 51 9615 0.16 25 10417 10417 0.00 95 10473 0.53 65 10417 0.00 47 10417 0.00 23 19.2k 19.23k 0.16 51 19.20k 0.00 35 19231 0.16 25 19.23k 0.16 12 57.6k 58.8k 2.12 16 57.60k 0.00 11 55556 -3.55 8 ? ? ? 115.2k ? ? ? 115.2k 0.00 5 ? ? ? ? ? ? baud rate sync = 0 , brgh = 1 f osc = 3.6864 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 ? ? ? 300 0.16 207 1200 1200 0.00 191 1202 0.16 51 2400 2400 0.00 95 2404 0.16 25 9600 9600 0.00 23 ? ? ? 10417 10473 0.53 21 10417 0.00 5 19.2k 19.2k 0.00 11 ? ? ? 57.6k 57.60k 0.00 3 ? ? ? 115.2k 115.2k 0.00 1 ? ? ? table 16-5: baud rates for asynchronous modes (continued)
pic16(l)f720/721 ds41430d-page 130 ? 2010-2013 microchip technology inc. 16.3 ausart synchronous mode synchronous serial communications are typically used in systems with a single master and one or more slaves. the master device contains the necessary circuitry for baud rate generation and supplies the clock for all devices in the system. slave devices can take advantage of the master clock by eliminating the internal clock generation circuitry. there are two signal lines in synchronous mode: a bidirectional data line and a clock line. slaves use the external clock supplied by the master to shift the serial data into and out of their respective receive and trans- mit shift registers. since the data line is bidirectional, synchronous operation is half-duplex only. half-duplex refers to the fact that master and slave devices can receive and transmit data but not both simultaneously. the ausart can operate as either a master or slave device. start and stop bits are not used in synchronous transmissions. 16.3.1 synchronous master mode the following bits are used to configure the ausart for synchronous master operation: ? sync = 1 ? csrc = 1 ? sren = 0 (for transmit); sren = 1 (for receive) ? cren = 0 (for transmit); cren = 1 (for receive) ? spen = 1 setting the sync bit of the txsta register configures the device for synchronous operation. setting the csrc bit of the txsta register configures the device as a master. clearing the sren and cren bits of the rcsta register ensures that the device is in the transmit mode, otherwise the device will be configured to receive. setting the spen bit of the rcsta register enables the ausart. 16.3.1.1 master clock synchronous data transfers use a separate clock line, which is synchronous with the data. a device config- ured as a master transmits the clock on the tx/ck line. the tx/ck pin output driver is automatically enabled when the ausart is configured for synchronous transmit or receive operation. serial data bits change on the leading edge to ensure they are valid at the trail- ing edge of each clock. one clock cycle is generated for each data bit. only as many clock cycles are generated as there are data bits. 16.3.1.2 synchronous master transmission data is transferred out of the device on the rx/dt pin. the rx/dt and tx/ck pin output drivers are automat- ically enabled when the ausart is configured for synchronous master transmit operation. a transmission is initiated by writing a character to the txreg register. if the tsr still contains all or part of a previous character, the new character data is held in the txreg until the last bit of the previous character has been transmitted. if this is the first character, or the previous character has been completely flushed from the tsr, the data in the txreg is immediately trans- ferred to the tsr. the transmission of the character commences immediately following the transfer of the data to the tsr from the txreg. each data bit changes on the leading edge of the master clock and remains valid until the subsequent leading clock edge. 16.3.1.3 synchronous master transmission setup: 1. initialize the spbrg register and the brgh bit to achieve the desired baud rate (refer to section 16.2 ?ausart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. disable receive mode by clearing bits sren and cren. 4. enable transmit mode by setting the txen bit. 5. if 9-bit transmission is desired, set the tx9 bit. 6. if interrupts are desired, set the txie bit of the pie1 register and the gie and peie bits of the intcon register. 7. if 9-bit transmission is selected, the ninth bit should be loaded in the tx9d bit. 8. start transmission by loading data to the txreg register. note: the tsr register is not mapped in data memory, so it is not available to the user.
? 2010-2013 microchip technology inc. ds41430d-page 131 pic16(l)f720/721 figure 16-6: synchronous t ransmission figure 16-7: synchronous transmission (through txen) bit 0 bit 1 bit 7 word 1 bit 2 bit 0 bit 1 bit 7 rx/dt write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: synchronous master mode, spbrg = 0 , continuous transmission of two 8-bit words. pin tx/ck pin rx/dt pin tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit table 16-6: registers associated wi th synchronous master transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 127 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txreg ausart transmit data register ? txsta csrc tx9 txen sync ? brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for synchronous master transmission.
pic16(l)f720/721 ds41430d-page 132 ? 2010-2013 microchip technology inc. 16.3.1.4 synchronous master reception data is received at the rx/dt pin. the rx/dt pin output driver is automatically disabled when the ausart is configured for synchronous master receive operation. in synchronous mode, reception is enabled by setting either the single receive enable bit (sren of the rcsta register) or the continuous receive enable bit (cren of the rcsta register). when sren is set and cren is clear, only as many clock cycles are generated as there are data bits in a single character. the sren bit is automatically cleared at the completion of one character. when cren is set, clocks are continuously generated until cren is cleared. if cren is cleared in the middle of a character the ck clock stops immediately and the partial charac- ter is discarded. if sren and cren are both set, then sren is cleared at the completion of the first character and cren takes precedence. to initiate reception, set either sren or cren. data is sampled at the rx/dt pin on the trailing edge of the tx/ck clock pin and is shifted into the receive shift register (rsr). when a complete character is received into the rsr, the rcif bit of the pir1 register is set and the character is automatically transferred to the two character receive fifo. the least significant eight bits of the top character in the receive fifo are available in rcreg. the rcif bit remains set as long as there are un-read characters in the receive fifo. 16.3.1.5 slave clock synchronous data transfers use a separate clock line, which is synchronous with the data. a device configured as a slave receives the clock on the tx/ck line. the tx/ ck pin output driver is automatically disabled when the device is configured for synchronous slave transmit or receive operation. serial data bits change on the leading edge to ensure they are valid at the trailing edge of each clock. one data bit is transferred for each clock cycle. only as many clock cycles should be received as there are data bits. 16.3.1.6 receive overrun error the receive fifo buffer can hold two characters. an overrun error will be generated if a third character, in its entirety, is received before rcreg is read to access the fifo. when this happens the oerr bit of the rcsta register is set. previous data in the fifo will not be overwritten. the two characters in the fifo buffer can be read, however, no additional characters will be received until the error is cleared. the oerr bit can only be cleared by clearing the overrun condition. if the overrun error occurred when the sren bit is set and cren is clear then the error is cleared by reading rcreg. if the overrun occurred when the cren bit is set then the error condition is cleared by either clearing the cren bit of the rcsta register. 16.3.1.7 receiving 9-bit characters the ausart supports 9-bit character reception. when the rx9 bit of the rcsta register is set, the ausart will shift nine bits into the rsr for each character received. the rx9d bit of the rcsta register is the ninth, and most significant, data bit of the top unread character in the receive fifo. when reading 9-bit data from the receive fifo buffer, the rx9d data bit must be read before reading the eight least significant bits from the rcreg. address detection in synchronous modes is not supported, therefore the adden bit of the rcsta register must be cleared. 16.3.1.8 synchronous master reception setup 1. initialize the spbrg register for the appropriate baud rate. set or clear the brgh bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, set the rcie bit of the pie1 register and the gie and peie bits of the intcon register. 5. if 9-bit reception is desired, set bit rx9. 6. verify address detection is disabled by clearing the adden bit of the rcsta register. 7. start reception by setting the sren bit or for continuous reception, set the cren bit. 8. interrupt flag bit rcif of the pir1 register will be set when reception of a character is complete. an interrupt will be generated if the rcie inter- rupt enable bit of the pie1 register was set. 9. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 10. read the 8-bit received data by reading the rcreg register. 11. if an overrun error occurs, clear the error by either clearing the cren bit of the rcsta register or by clearing the spen bit, which resets the ausart.
? 2010-2013 microchip technology inc. ds41430d-page 133 pic16(l)f720/721 figure 16-8: synchronous reception (master mode, sren) cren bit rx/dt write to bit sren sren bit rcif bit (interrupt) read rcreg ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? note: timing diagram demonstrates synchronous master mode with bit sren = 1 and bit brgh = 0 . tx/ck pin pin table 16-7: registers associated with synchronous master reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcreg ausart receive data register 123 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txsta csrc tx9 txen sync ?brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for synchronous master reception.
pic16(l)f720/721 ds41430d-page 134 ? 2010-2013 microchip technology inc. 16.3.2 synchronous slave mode the following bits are used to configure the ausart for synchronous slave operation: ? sync = 1 ? csrc = 0 ? sren = 0 (for transmit); sren = 1 (for receive) ? cren = 0 (for transmit); cren = 1 (for receive) ? spen = 1 setting the sync bit of the txsta register configures the device for synchronous operation. clearing the csrc bit of the txsta register configures the device as a slave. clearing the sren and cren bits of the rcsta register ensures that the device is in the transmit mode, otherwise the device will be configured to receive. setting the spen bit of the rcsta register enables the ausart. 16.3.2.1 ausart synchronous slave transmit the operation of the synchronous master and slave modes are identical (refer to section 16.3.1.2 ?synchronous master transmission? ) , except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: 1. the first character will immediately transfer to the tsr register and transmit. 2. the second word will remain in txreg register. 3. the txif bit will not be set. 4. after the first character has been shifted out of tsr, the txreg register will transfer the second character to the tsr and the txif bit will now be set. 5. if the peie and txie bits are set, the interrupt will wake the device from sleep and execute the next instruction. if the gie bit is also set, the program will call the interrupt service routine. 16.3.2.2 synchronous slave transmission setup 1. set the sync and spen bits and clear the csrc bit. 2. clear the cren and sren bits. 3. if using interrupts, ensure that the gie and peie bits of the intcon register are set and set the txie bit. 4. if 9-bit transmission is desired, set the tx9 bit. 5. enable transmission by setting the txen bit. 6. verify address detection is disabled by clearing the adden bit of the rcsta register. 7. if 9-bit transmission is selected, insert the most significant bit into the tx9d bit. 8. start transmission by writing the least significant 8 bits to the txreg register. table 16-8: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txreg ausart transmit data register ? txsta csrc tx9 txen sync ? brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for synchronous slave transmission.
? 2010-2013 microchip technology inc. ds41430d-page 135 pic16(l)f720/721 16.3.2.3 ausart synchronous slave reception the operation of the synchronous master and slave modes is identical ( section 16.3.1.4 ?synchronous master reception? ), with the following exceptions: ? sleep ? cren bit is always set, therefore the receiver is never idle ? sren bit, which is a ?don?t care? in slave mode a character may be received while in sleep mode by setting the cren bit prior to entering sleep. once the word is received, the rsr register will transfer the data to the rcreg register. if the rcie interrupt enable bit of the pie1 register is set, the interrupt generated will wake the device from sleep and execute the next instruction. if the gie bit is also set, the program will branch to the interrupt vector. 16.3.2.4 synchronous slave reception setup 1. set the sync and spen bits and clear the csrc bit. 2. if interrupts are desired, set the rcie bit of the pie1 register and the gie and peie bits of the intcon register. 3. if 9-bit reception is desired, set the rx9 bit. 4. verify address detection is disabled by clearing the adden bit of the rcsta register. 5. set the cren bit to enable reception. 6. the rcif bit of the pir1 register will be set when reception is complete. an interrupt will be generated if the rcie bit of the pie1 register was set. 7. if 9-bit mode is enabled, retrieve the most significant bit from the rx9d bit of the rcsta register. 8. retrieve the 8 least significant bits from the receive fifo by reading the rcreg register. 9. if an overrun error occurs, clear the error by either clearing the cren bit of the rcsta register. table 16-9: registers associated with synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 rcreg ausart receive data register 123 rcsta spen rx9 sren cren adden ferr oerr rx9d 126 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 txsta csrc tx9 txen sync ? brgh trmt tx9d 125 legend: x = unknown, - = unimplemented read as ? 0 ?. shaded cells are not used for synchronous slave reception.
pic16(l)f720/721 ds41430d-page 136 ? 2010-2013 microchip technology inc. 16.4 ausart operation during sleep the ausart will remain active during sleep only in the synchronous slave mode. all other modes require the system clock and therefore cannot generate the necessary signals to run the transmit or receive shift registers during sleep. synchronous slave mode uses an externally generated clock to run the transmit and receive shift registers. 16.4.1 synchronous receive during sleep to receive during sleep, all the following conditions must be met before entering sleep mode: ? rcsta and txsta control registers must be configured for synchronous slave reception (refer to section 16.3.2.4 ?synchronous slave reception setup? ). ? if interrupts are desired, set the rcie bit of the pie1 register and the peie bit of the intcon register. ? the rcif interrupt flag must be cleared by reading rcreg to unload any pending characters in the receive buffer. upon entering sleep mode, the device will be ready to accept data and clocks on the rx/dt and tx/ck pins, respectively. when the data word has been completely clocked in by the external device, the rcif interrupt flag bit of the pir1 register will be set. thereby, waking the processor from sleep. upon waking from sleep, the instruction following the sleep instruction will be executed. if the gie, global interrupt enable bit of the intcon register is also set, then the interrupt service routine at address 0004h will be called. 16.4.2 synchronous transmit during sleep to transmit during sleep, all the following conditions must be met before entering sleep mode: ? rcsta and txsta control registers must be configured for synchronous slave transmission (refer to section 16.3.2.2 ?synchronous slave transmission setup? ). ? the txif interrupt flag must be cleared by writing the output data to the txreg, thereby filling the tsr and transmit buffer. ? if interrupts are desired, set the txie bit of the pie1 register and the peie bit of the intcon register. upon entering sleep mode, the device will be ready to accept clocks on the tx/ck pin and transmit data on the rx/dt pin. when the data word in the tsr has been completely clocked out by the external device, the pending byte in the txreg will transfer to the tsr and the txif flag will be set. thereby, waking the processor from sleep. at this point, the txreg is available to accept another character for transmission, which will clear the txif flag. upon waking from sleep, the instruction following the sleep instruction will be executed. if the gie, global interrupt enable bit is also set then the interrupt service routine at address 0004h will be called.
? 2010-2013 microchip technology inc. ds41430d-page 137 pic16(l)f720/721 17.0 ssp module overview the synchronous serial port (ssp) module is a serial interface useful for communicating with other peripher- als or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, display drivers, a/d converters, etc. the ssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit (i 2 c?) 17.1 spi mode the spi mode allows eight bits of data to be synchro- nously transmitted and received, simultaneously. the ssp module can be operated in one of two spi modes: ?master mode ? slave mode spi is a full-duplex protocol, with all communication being bidirectional and initiated by a master device. all clocking is provided by the master device and all bits are transmitted, msb first. care must be taken to ensure that all devices on the spi bus are setup to allow all controllers to send and receive data at the same time. a typical spi connection between microcontroller devices is shown in figure 17-1 . addressing of more than one slave device is accomplished via multiple hardware slave select lines. external hardware and additional i/o pins must be used to support multiple slave select addressing. this prevents extra overhead in software for communication. for spi communication, typically three pins are used: ? serial data out (sdo) ? serial data in (sdi) ? serial clock (sck) additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ss ) figure 17-1: typical spi mast er/slave connection serial input buffer (sspbuf) shift register (sspsr) msb lsb sdo sdi processor 1 sck spi master sspm<3:0> = 00xx serial input buffer (sspbuf) shift register (sspsr) lsb msb sdi sdo processor 2 sck spi slave sspm<3:0> = 010x serial clock ss slave select general i/o (optional)
pic16(l)f720/721 ds41430d-page 138 ? 2010-2013 microchip technology inc. figure 17-2: spi mode block diagram read write internal data bus sdi sdo ra5/ss sck sspsr reg sspbuf reg sspm<3:0> bit 0 shift clock ss control enable edge select clock select tmr2 f osc prescaler 4, 16, 64 trisx 2 4 ra0/ss sssel output ? 2 edge select bit 7
? 2010-2013 microchip technology inc. ds41430d-page 139 pic16(l)f720/721 17.1.1 master mode in master mode, data transfer can be initiated at any time because the master controls the sck line. master mode determines when the slave ( figure 17-1 , processor 2) transmits data via control of the sck line. 17.1.1.1 master mode operation the ssp consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr register shifts the data in and out of the device, msb first. the sspbuf register holds the data that is written out of the master until the received data is ready. once the eight bits of data have been received, the byte is moved to the sspbuf register. the buffer full status bit, bf of the sspstat register, and the ssp interrupt flag bit, sspif of the pir1 register, are then set. any write to the sspbuf register during transmission/ reception of data will be ignored and the write collision detect bit, wcol of the sspcon register, will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspbuf register completed successfully. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data is written to the sspbuf. the bf bit of the sspstat register is set when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. the ssp interrupt may be used to determine when the transmission/reception is complete and the sspbuf must be read and/or written. if interrupts are not used, then software polling can be done to ensure that a write collision does not occur. example 17-1 shows the loading of the sspbuf (sspsr) for data transmission. 17.1.1.2 enabling master i/o to enable the serial port, the sspen bit of the sspcon register, must be set. to reset or reconfigure spi mode, clear the sspen bit, re-initialize the sspcon register and then set the sspen bit. if a master mode of operation is selected in the sspm bits of the sspcon register, the sdi, sdo and sck pins will be assigned as serial port pins. for these pins to function as serial port pins, they must have their corresponding data direction bits set or cleared in the associated tris register as follows: ? sdi configured as input ? sdo configured as output ? sck configured as output 17.1.1.3 master mode setup in master mode, the data is transmitted/received as soon as the sspbuf register is loaded with a byte value. if the master is only going to receive, sdo output could be disabled (programmed and used as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. when initializing spi master mode operation, several options need to be specified. this is accomplished by programming the appropriate control bits in the sspcon and sspstat registers. these control bits allow the following to be specified: ? sck as clock output ? idle state of sck (ckp bit) ? data input sample phase (smp bit) ? output data on rising/falling edge of sck (cke bit) ? clock bit rate in master mode, the spi clock rate (bit rate) is user selectable to be one of the following: ?f osc /4 (or tcy) ?f osc /16 (or 4 ? tcy) ?f osc /64 (or 16 ? tcy) ? (timer2 output)/2 this allows a maximum data rate of 5 mbps (at f osc =16mhz). figure 17-3 shows the waveforms for master mode. the clock polarity is selected by appropriately program- ming the ckp bit of the sspcon register. when the cke bit is set, the sdo data is valid before there is a clock edge on sck. the sample time of the input data is shown based on the state of the smp bit and can occur at the middle or end of the data output time. the time when the sspbuf is loaded with the received data is shown. 17.1.1.4 sleep in master mode in master mode, all module clocks are halted and the transmission/reception will remain in their current state, paused, until the device wakes from sleep. after the device wakes up from sleep, the module will continue to transmit/receive data. note: the sspsr is not directly readable or writable and can only be accessed by addressing the sspbuf register.
pic16(l)f720/721 ds41430d-page 140 ? 2010-2013 microchip technology inc. figure 17-3: spi master mode waveform example 17-1: loading the sspbuf (sspsr) register sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 4 clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 0 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) banksel sspstat ; loop btfss sspstat, bf ;has data been received(transmit complete)? goto loop ;no banksel sspbuf ; movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
? 2010-2013 microchip technology inc. ds41430d-page 141 pic16(l)f720/721 17.1.2 slave mode for any spi device acting as a slave, the data is transmitted and received as external clock pulses appear on sck pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. 17.1.2.1 slave mode operation the ssp consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr until the received data is ready. the slave has no control as to when data will be clocked in or out of the device. all data that is to be transmitted, to a master or another slave, must be loaded into the sspbuf register before the first clock pulse is received. once eight bits of data have been received: ? received byte is moved to the sspbuf register ? bf bit of the sspstat register is set ? sspif bit of the pir1 register is set any write to the sspbuf register during transmission/ reception of data will be ignored and the write collision detect bit, wcol of the sspcon register, will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspbuf register completed successfully. the user?s firmware must read sspbuf, clearing the bf flag, or the sspov bit of the sspcon register will be set with the reception of the next byte and communication will be disabled. a spi module transmits and receives at the same time, occasionally causing dummy data to be transmitted/ received. it is up to the user to determine which data is to be used and what can be discarded. 17.1.2.2 enabling slave i/o to enable the serial port, the sspen bit of the sspcon register must be set. if a slave mode of operation is selected in the sspm bits of the sspcon register, the sdi, sdo and sck pins will be assigned as serial port pins. for these pins to function as serial port pins, they must have their corresponding data direction bits set or cleared in the associated tris register as follows: ? sdi configured as input ? sdo configured as output ? sck configured as input optionally, a fourth pin, slave select (ss ) may be used in slave mode. slave select may be configured to operate on the rc6/ss pin via the sssel bit in the apfcon register. upon selection of a slave select pin, the appropriate bits must be set in the ansela and trisa registers. slave select must be set as an input by setting the corresponding bit in trisa, and digital i/o must be enabled on the ss pin by clearing the corresponding bit of the ansela register. 17.1.2.3 slave mode setup when initializing the ssp module to spi slave mode, compatibility must be ensured with the master device. this is done by programming the appropriate control bits of the sspcon and sspstat registers. these control bits allow the following to be specified: ? sck as clock input ? idle state of sck (ckp bit) ? data input sample phase (smp bit) ? output data on rising/falling edge of sck (cke bit) figure 17-4 and figure 17-5 show example waveforms of slave mode operation.
pic16(l)f720/721 ds41430d-page 142 ? 2010-2013 microchip technology inc. figure 17-4: spi mode waveform (slave mode with cke = 0 ) figure 17-5: spi mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag optional sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag not optional
? 2010-2013 microchip technology inc. ds41430d-page 143 pic16(l)f720/721 17.1.2.4 slave select operation the ss pin allows synchronous slave mode operation. the spi must be in slave mode with ss pin control enabled (sspm<3:0> = 0100 ). the associated tris bit for the ss pin must be set, making ss an input. in slave select mode, when: ?ss = 0 , the device operates as specified in section 17.1.2 ?slave mode? . ?ss = 1 , the spi module is held in reset and the sdo pin will be tri-stated. when the spi module resets, the bit counter is cleared to ? 0 ?. this can be done by either forcing the ss pin to a high level or clearing the sspen bit. figure 17-6 shows the timing waveform for such a synchronization event. 17.1.2.5 sleep in slave mode while in sleep mode, the slave can transmit/receive data. the spi transmit/receive shift register operates asynchronously to the device on the externally supplied clock source. this allows the device to be placed in sleep mode and data to be shifted into the spi transmit/receive shift register. when all eight bits have been received, the ssp interrupt flag bit will be set and, if enabled, will wake the device from sleep. figure 17-6: slave select synchro nization waveform note 1: when the spi is in slave mode with ss pin control enabled (sspm<3:0> = 0100 ), the spi module will reset if the ss pin is driven high. 2: if the spi is used in slave mode with cke set, the ss pin control must be enabled. note: sspsr must be reinitialized by writing to the sspbuf register before the data can be clocked out of the slave again. sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 7 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag bit 0 bit 7 bit 0 sspsr must be reinitialized by writing to the sspbuf register before the data can be clocked out of the slave again.
pic16(l)f720/721 ds41430d-page 144 ? 2010-2013 microchip technology inc. register 17-1: sspcon: sync serial po rt control register (spi mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol : write collision detect bit 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov : receive overflow indicator bit 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode. the user must read the sspbuf, even if only transmitting data, to avoid setting overflow. in master mode the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register. 0 = no overflow bit 5 sspen : synchronous serial port enable bit 1 = enables serial port and configures sck, sdo and sdi as serial port pins (1) 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp : clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm<3:0> : synchronous serial port mode select bits 0000 = spi master mode, clock = f osc /4 0001 = spi master mode, clock = f osc /16 0010 = spi master mode, clock = f osc /64 0011 = spi master mode, clock = tmr2 output/2 0100 = spi slave mode, clock = sck pin. ss pin control enabled. 0101 = spi slave mode, clock = sck pin. ss pin control disabled. ss can be used as i/o pin. note 1: when enabled, these pins must be properly configured as input or output.
? 2010-2013 microchip technology inc. ds41430d-page 145 pic16(l)f720/721 register 17-2: sspstat: sync serial port status register (spi mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp : spi data input sample phase bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode bit 6 cke : spi clock edge select bit spi mode, ckp = 0 : 1 = data stable on rising edge of sck 0 = data stable on falling edge of sck spi mode, ckp = 1 : 1 = data stable on falling edge of sck 0 = data stable on rising edge of sck bit 5 d/a : data/address bit used in i 2 c mode only. bit 4 p: stop bit used in i 2 c mode only. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write information bit used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf : buffer full status bit 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty
pic16(l)f720/721 ds41430d-page 146 ? 2010-2013 microchip technology inc. table 17-1: summary of registers associated with spi operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page anselc ansc7 ansc6 ? ? ansc3 ansc2 ansc1 ansc0 61 intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 pr2 timer2 module period register 105 sspbuf synchronous serial port receive buffer/transmit register 139 sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 144 sspstat smp cke d/a p s r/w ua bf 145 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 61 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 106 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the ssp in spi mode.
? 2010-2013 microchip technology inc. ds41430d-page 147 pic16(l)f720/721 17.2 i 2 c mode the ssp module, in i 2 c mode, implements all slave functions except general call support. it provides interrupts on start and stop bits in hardware to facilitate firmware implementations of the master functions. the ssp module implements the i 2 c standard mode specifications: ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ? start and stop bit interrupts enabled to support firmware master mode ?address masking two pins are used for data transfer; the scl pin (clock line) and the sda pin (data line). the user must configure the two pin?s data direction bits as inputs in the appropriate tris register. upon enabling i 2 c mode, the i 2 c slew rate limiters in the i/o pads are controlled by the smp bit of sspstat register. the ssp module functions are enabled by setting the sspen bit of sspcon register. data is sampled on the rising edge and shifted out on the falling edge of the clock. this ensures that the sda signal is valid during the scl high time. the scl clock input must have minimum high and low times for proper operation. refer to section 23.0 ?electrical specifications? . figure 17-7: i 2 c? mode block diagram figure 17-8: typical i 2 c? connections the ssp module has six registers for i 2 c operation. they are: ? ssp control (sspcon) register ? ssp status (sspstat) register ? serial receive/transmit buffer (sspbuf) register ? ssp shift register (sspsr), not directly accessible ? ssp address (sspadd) register ? ssp address mask (sspmsk) register 17.2.1 hardware setup selection of i 2 c mode, with the sspen bit of the sspcon register set, forces the scl and sda pins to be open drain, provided these pins are programmed as inputs by setting the appropriate trisc bits. the ssp module will override the input state with the output data, when required, such as for acknowledge and slave- transmitter sequences. read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match scl sda shift clock msb lsb sspmsk reg note: pull-up resistors must be provided externally to the scl and sda pins for proper operation of the i 2 c module. slave 1 master sda scl v dd v dd sda scl slave 2 sda scl (optional)
pic16(l)f720/721 ds41430d-page 148 ? 2010-2013 microchip technology inc. 17.2.2 start and stop conditions during times of no data transfer (idle time), both the clock line (scl) and the data line (sda) are pulled high through external pull-up resistors. the start and stop conditions determine the start and stop of data trans- mission. the start condition is defined as a high-to-low transition of the sda line while scl is high. the stop condition is defined as a low-to-high transition of the sda line while scl is high. figure 17-9 shows the start and stop conditions. a master device generates these conditions for starting and terminating data transfer. due to the definition of the start and stop conditions, when data is being trans- mitted, the sda line can only change state when the scl line is low. figure 17-9: start and stop conditions 17.2.3 acknowledge after the valid reception of an address or data byte, the hardware automatically will generate the acknowledge (ack ) pulse and load the sspbuf register with the received value currently in the sspsr register. there are certain conditions that will cause the ssp module not to generate this ack pulse. they include any or all of the following: ? the buffer full bit, bf of the sspstat register, was set before the transfer was received. ? the ssp overflow bit, sspov of the sspcon register, was set before the transfer was received. ? the ssp module is being operated in firmware master mode. in such a case, the sspsr register value is not loaded into the sspbuf, but bit sspif of the pir1 register is set. tab l e 1 7- 2 shows the results of when a data transfer byte is received, given the status of bits bf and sspov. flag bit bf is cleared by reading the sspbuf register, while bit sspov is cleared through software. sda scl p stop condition s start condition change of data allowed change of data allowed table 17-2: data transfer received byte actions status bits as data transfer is received sspsr ? sspbuf generate ack pulse set bit sspif (ssp interrupt occurs if enabled) bf sspov 00 yes yes yes 10 no no yes 11 no no yes 0 1 no no yes note 1: shaded cells show the conditions where the user software did not properly clear the overflow condition.
? 2010-2013 microchip technology inc. ds41430d-page 149 pic16(l)f720/721 17.2.4 addressing once the ssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8 bits are shifted into the sspsr register. all incom- ing bits are sampled with the rising edge of the clock line (scl). 17.2.4.1 7-bit addressing in 7-bit addressing mode ( figure 17-10 ), the value of register sspsr<7:1> is compared to the value of reg- ister sspadd<7:1>. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match, and the bf and sspov bits are clear, the following events occur: ? the sspsr register value is loaded into the sspbuf register. ? the bf bit is set. ?an ack pulse is generated. ? ssp interrupt flag bit, sspif of the pir1 register, is set (interrupt is generated if enabled) on the falling edge of the ninth scl pulse. 17.2.4.2 10-bit addressing in 10-bit address mode, two address bytes need to be received by the slave ( figure 17-11 ). the five most significant bits (msbs) of the first address byte specify if it is a 10-bit address. the r/w bit of the sspstat register must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 1111 0 a9 a8 0 ?, where a9 and a8 are the two msbs of the address. the sequence of events for 10-bit address is as follows for reception: 1. load sspadd register with high byte of address. 2. receive first (high) byte of address (bits sspif, bf and ua of the sspstat register are set). 3. read the sspbuf register (clears bit bf). 4. clear the sspif flag bit. 5. update the sspadd register with second (low) byte of address (clears ua bit and releases the scl line). 6. receive low byte of address (bits sspif, bf and ua are set). 7. update the sspadd register with the high byte of address. if match releases scl line, this will clear bit ua. 8. read the sspbuf register (clears bit bf). 9. clear flag bit sspif. if data is requested by the master, once the slave has been addressed: 1. receive repeated start condition. 2. receive repeat of high byte address with r/w = 1 , indicating a read. 3. bf bit is set and the ckp bit is cleared, stopping scl and indicating a read request. 4. sspbuf is written, setting bf, with the data to send to the master device. 5. ckp is set in software, releasing the scl line. 17.2.4.3 address masking the address masking register (sspmsk) is only accessible while the sspm bits of the sspcon register are set to ? 1001 ?. in this register, the user can select which bits of a received address the hardware will compare when determining an address match. any bit that is set to a zero in the sspmsk register, the corresponding bit in the received address byte and sspadd register are ignored when determining an address match. by default, the register is set to all ones, requiring a complete match of a 7-bit address or the lower eight bits of a 10-bit address.
pic16(l)f720/721 ds41430d-page 150 ? 2010-2013 microchip technology inc. 17.2.5 reception when the r/w bit of the received address byte is clear, the master will write data to the slave. if an address match occurs, the received address is loaded into the sspbuf register. an address byte overflow will occur if that loaded address is not read from the sspbuf before the next complete byte is received. an ssp interrupt is generated for each data transfer byte. the bf, r/w and d/a bits of the sspstat register are used to determine the status of the last received byte. figure 17-10: i 2 c? waveforms for reception (7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 1 2 34 56 78 9123 4 567 89 12 34 bus master sends stop condition bit sspov is set because the sspbuf register is still full. cleared in software sspbuf register is read ack receiving data receiving data d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 0 receiving address sspif bf sspov ack ack is not sent.
? 2010-2013 microchip technology inc. ds41430d-page 151 pic16(l)f720/721 figure 17-11: i 2 c? slave mode timing (reception, 10-bit address) sspif bf receive data byte r/w receive first byte of address cleared in software cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ckp receive data byte bus master sends stop condition ack cleared in software cleared in software sspov sspov is set because sspbuf is still full. ack is not sent. clock is held low until update of sspadd has taken place sda scl s 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 7 8 9 p 1 1 1 1 0 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 d7 d6 d5 d4 d3 d1 d0 ack ack d2 6 ack 1 2 3 4 5 7 8 9 d7 d6 d5 d4 d3 d1 d0 d2 6 ack 0
pic16(l)f720/721 ds41430d-page 152 ? 2010-2013 microchip technology inc. 17.2.6 transmission when the r/w bit of the received address byte is set and an address match occurs, the r/w bit of the sspstat register is set and the slave will respond to the master by reading out data. after the address match, an ack pulse is generated by the slave hardware and the scl pin is held low (clock is automatically stretched) until the slave is ready to respond. see section 17.2.7 ?clock stretching? . the data the slave will transmit must be loaded into the sspbuf register, which sets the bf bit. the scl line is released by setting the ckp bit of the sspcon register. an ssp interrupt is generated for each transferred data byte. the sspif flag bit of the pir1 register initiates an ssp interrupt, and must be cleared by software before the next byte is transmitted. the bf bit of the sspstat register is cleared on the falling edge of the 8th received clock pulse. the sspif flag bit is set on the falling edge of the ninth clock pulse. following the 8th falling clock edge, control of the sda line is released back to the master so that the master can acknowledge or not acknowledge the response. if the master sends a not acknowledge, the slave?s transmission is complete and the slave must monitor for the next start condition. if the master acknowledges, control of the bus is returned to the slave to transmit another byte of data. just as with the previous byte, the clock is stretched by the slave, data must be loaded into the sspbuf and ckp must be set to release the clock line (scl). figure 17-12: i 2 c waveforms for transmission (7-bit address) sda scl sspif bf ckp a7 a6 a5 a4 a3 a2 a1 ack d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data r/w receiving address 123456789 123456789 p cleared in software set bit after writing to sspbuf s data in sampled scl held low while cpu responds to sspif (the sspbuf must be written to before the ckp bit can be set) dummy read of sspbuf to clear bf flag sspbuf is written in software from ssp interrupt service routine
? 2010-2013 microchip technology inc. ds41430d-page 153 pic16(l)f720/721 figure 17-13: i 2 c slave mode timing (transmission 10-bit address) sda scl sspif bf s 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 7 8 9 p 1 1 1 1 0 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master sends stop condition a9 6 receive second byte of address cleared by hardware when sspadd is updated with low byte of address. ua clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address. sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag receive first byte of address 1 2 3 4 5 7 8 9 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspbuf to clear bf flag sr cleared in software write of sspbuf cleared in software completion of clears bf flag ckp ckp is set in software, initiates transmission ckp is automatically cleared in hardware holding scl low clock is held low until update of sspadd has taken place data transmission clock is held low until ckp is set to ? 1 ? bus master sends restarts condition dummy read of sspbuf to clear bf flag
pic16(l)f720/721 ds41430d-page 154 ? 2010-2013 microchip technology inc. 17.2.7 clock stretching during any scl low phase, any device on the i 2 c bus may hold the scl line low and delay, or pause, the transmission of data. this ?stretching? of a transmission allows devices to slow down communication on the bus. the scl line must be constantly sampled by the master to ensure that all devices on the bus have released scl for more data. stretching usually occurs after an ack bit of a transmission, delaying the first bit of the next byte. the ssp module hardware automatically stretches for two conditions: ? after a 10-bit address byte is received (update sspadd register) ? anytime the ckp bit of the sspcon register is cleared by hardware the module will hold scl low until the ckp bit is set. this allows the user slave software to update sspbuf with data that may not be readily available. in 10-bit addressing modes, the sspadd register must be updated after receiving the first and second address bytes. the ssp module will hold the scl line low until the sspadd has a byte written to it. the ua bit of the sspstat register will be set, along with sspif, indicating an address update is needed. 17.2.8 firmware master mode master mode of operation is supported in firmware using interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits of the sspstat register are cleared from a reset or when the ssp module is disabled (sspen cleared). the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when the p bit is set or the bus is idle and both the s and p bits are clear. in firmware master mode, the scl and sda lines are manipulated by setting/clearing the corresponding tris bit(s). the output level is always low, irrespective of the value(s) in the corresponding port register bit(s). when transmitting a ? 1 ?, the tris bit must be set (input) and a ? 0 ?, the tris bit must be clear (output). the following events will cause the ssp interrupt flag bit, sspif, to be set (ssp interrupt will occur if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received firmware master mode of operation can be done with either the slave mode idle (sspm<3:0> = 1011 ), or with either of the slave modes in which interrupts are enabled. when both master and slave functionality is enabled, the software needs to differentiate the source(s) of the interrupt. refer to application note an554, ? software implementation of i 2 c? bus master ? (ds00554) for more information. 17.2.9 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allow the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the ssp module is disabled. the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when the p bit of the sspstat register is set or when the bus is idle, and both the s and p bits are clear. when the bus is busy, enabling the ssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be moni- tored to see if the signal level is the expected output level. this check only needs to be done when a high level is output. if a high level is expected and a low level is present, the device needs to release the sda and scl lines (set tris bits). there are two stages where this arbitration of the bus can be lost. they are the address transfer and data transfer stages. when the slave logic is enabled, the slave continues to receive. if arbitration was lost during the address transfer stage, communication to the device may be in progress. if addressed, an ack pulse will be generated. if arbitration was lost during the data transfer stage, the device will need to re-transfer the data at a later time. refer to application note an578, ? use of the ssp module in the i 2 c? multi-master environment ? (ds00578) for more information.
? 2010-2013 microchip technology inc. ds41430d-page 155 pic16(l)f720/721 17.2.10 clock synchronization when the ckp bit is cleared, the scl output is held low once it is sampled low. therefore, the ckp bit will not stretch the scl line until an external i 2 c master device has already asserted the scl line low. the scl output will remain low until the ckp bit is set and all other devices on the i 2 c bus have released scl. this ensures that a write to the ckp bit will not violate the minimum high time requirement for scl ( figure 17-14 ). 17.2.11 sleep operation while in sleep mode, the i 2 c module can receive addresses of data, and when an address match or complete byte transfer occurs, wake the processor from sleep (if ssp interrupt is enabled). figure 17-14: clock synchronization timing sda scl dx-1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspcon ckp master device de-asserts clock master device asserts clock
pic16(l)f720/721 ds41430d-page 156 ? 2010-2013 microchip technology inc. register 17-3: sspcon: synchronous se rial port control register (i 2 c mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol : write collision detect bit 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov : receive overflow indicator bit 1 = a byte is received while the sspbuf register is still holding the previous byte. sspov is a ?don?t care? in transmit mode. sspov must be cleared in software in either mode. 0 = no overflow bit 5 sspen : synchronous serial port enable bit 1 = enables the serial port and configures the sda and scl pins as serial port pins (2) 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp : clock polarity select bit 1 = release control of scl 0 = holds clock low (clock stretch). (used to ensure data setup time.) bit 3-0 sspm<3:0> : synchronous serial port mode select bits 0110 = i 2 c slave mode, 7-bit address 0111 = i 2 c slave mode, 10-bit address 1000 = reserved 1001 = load sspmsk register at sspadd sfr address (1) 1010 = reserved 1011 = i 2 c firmware controlled master mode (slave idle) 1100 = reserved 1101 = reserved 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled note 1: when this mode is selected, any reads or writes to the sspadd sfr address accesses the sspmsk register. 2: when enabled, these pins must be properly configured as input or output using the associated tris bit.
? 2010-2013 microchip technology inc. ds41430d-page 157 pic16(l)f720/721 register 17-4: sspstat: synchronous serial port status register (i 2 c mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp : spi data input sample phase bit 1 = slew rate control (limiting) disabled. operating in i 2 c standard mode (100 khz and 1 mhz). 0 = slew rate control (limiting) enabled. operating in i 2 c fast mode (400 khz). bit 6 cke : spi clock edge select bit this bit must be maintained clear. used in spi mode only. bit 5 d/a : data/address bit (i 2 c mode only) 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p : stop bit this bit is cleared when the ssp module is disabled, or when the start bit is detected last. 1 = indicates that a stop bit has been detected last (this bit is ? 0 ? on reset) 0 = stop bit was not detected last bit 3 s : start bit this bit is cleared when the ssp module is disabled, or when the stop bit is detected last. 1 = indicates that a start bit has been detected last (this bit is ? 0 ? on reset) 0 = start bit was not detected last bit 2 r/w : read/write bit information this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or ack bit. 1 = read 0 = write bit 1 ua : update address bit (10-bit i 2 c mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf : buffer full status bit receive: 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty transmit: 1 = transmit in progress, sspbuf is full 0 = transmit complete, sspbuf is empty
pic16(l)f720/721 ds41430d-page 158 ? 2010-2013 microchip technology inc. register 17-5: sspmsk: ssp mask register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 msk<7:1>: mask bits 1 = the received address bit n is compared to sspadd to detect i 2 c address match 0 = the received address bit n is not used to detect i 2 c address match bit 0 msk<0>: mask bit for i 2 c slave mode, 10-bit address i 2 c slave mode, 10-bit address (sspm<3:0> = 0111 ): 1 = the received address bit ? 0 ? is compared to sspadd<0> to detect i 2 c address match 0 = the received address bit ? 0 ? is not used to detect i 2 c address match all other ssp modes: this bit has no effect. register 17-6: sspadd: ssp i 2 c address register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 add7 add6 add5 add4 add3 add2 add1 add0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 add<7:0>: address bits received address table 17-3: registers associated with i 2 c operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 sspbuf synchronous serial port receive buffer/transmit register 139 sspadd add<7:0> 158 sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 156 sspmsk (2) msk<7:0> 158 sspstat smp (1) cke (1) d/a psr/w ua bf 145 trisb trisb7 trisb6 trisb5 trisb4 ? ? ? ? 55 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by ssp module in i 2 c mode. note 1: maintain these bits clear in i 2 c mode. 2: accessible only when sspm<3:0> = 1001 .
? 2010-2013 microchip technology inc. ds41430d-page 159 pic16(l)f720/721 18.0 flash program memory self read/self write control the flash program memory is readable and writable during normal operation of the device. this memory is not directly mapped in the register file space. instead, it is indirectly addressed through the special function registers. there are six sfrs used to read/write this memory: ?pmcon1 ?pmcon2 ?pmdatl ?pmdath ? pmadrl ? pmadrh when interfacing the program memory block, the pmdatl and pmdath registers form a two byte word which holds the 14-bit program data for reading, and the pmadrl and pmadrh registers form a two byte word which holds the 13-bit address of the program flash location being accessed. these devices have 2k to 4k words of program memory with an address range from 0000h to 0fffh. devices without a full map of memory will shadow accesses to unused blocks back to the implemented memory. 18.1 program memory read operation to read a program memory location, the user must write two bytes of the address to the pmadrh and pmadrl registers, then set control bit rd (pmcon1<0>). once the read control bit is set, the program memory read (pmr) controller uses the two instruction cycles to read the data. this causes the two instructions immediately following the ?bsf pmcon1, rd? instruction to be ignored. the data is available in the third cycle, following the set of the rd bit, in the pmdath and pmdatl registers. pmdatl and pmdath registers will hold this value until another read is executed. see example 18-1 and figure 18-1 for more information. example 18-1: flash program memory read note: interrupts must be disabled during the time from setting pmcon1<0> (rd) to the third instruction thereafter. * this code block will read 1 word of program * memory at the memory address: prog_addr_hi: prog_addr_lo * data will be returned in the variables; * prog_data_hi, prog_data_lo banksel pmadrl ; select bank 2 movlw prog_addr_lo ; movwf pmadrl ; store lsb of address movlw prog_addr_hi ; movwl pmadrh ; store msb of address banksel pmcon1 ; select bank 3 bcf intcon,gie ; disable interrupts bsf pmcon1,rd ; initiate read nop ; ignored ( figure 18-1 ) nop ; ignored ( figure 18-1 ) bsf intcon,gie ; restore interrupts banksel pmdatl ; select bank 2 movf pmdatl,w ; get lsb of word movwf prog_data_lo ; store in user location movf pmdath,w ; get msb of word movwf prog_data_hi ; store in user location
pic16(l)f720/721 ds41430d-page 160 ? 2010-2013 microchip technology inc. figure 18-1: flash program memory re ad cycle execution ? normal mode 18.2 code protection when the device is code-protected, the cpu may continue to read and write the flash program memory. depending on the settings of the flash program memory enable (wrt<1:0>) bits, the device may or may not be able to write certain blocks of the program memory. however, reads of the program memory are allowed. when the flash program memory code protection (cp) bit in the configuration word register is enabled, the program memory is code-protected, and the device programmer (icsp?) cannot access data or program memory. 18.3 pmadrh and pmadrl registers the pmadrh:pmadrl register pair can address up to a maximum of 4k words of program flash. the most significant byte (msb) of the address is written to the pmadrh register and the least significant byte (lsb) is written to the pmadrl register. 18.4 pmcon1 and pmcon2 registers pmcon1 is the control register for the data program memory accesses. control bits rd and wr initiate read and write, respectively. these bits cannot be cleared, but only set in software. they are cleared in hardware at the completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental premature termination of a write operation. setting the control bit wr initiates a write operation. for program memory writes, wr initiates a write cycle if free = 0 and an erase cycle if free = 1 . the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. pmcon2 is not a physical register. reading pmcon2 will read all ? 0 ?s. the pmcon2 register is used exclusively in the flash memory write sequence. q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bsf pmcon1, rd executed here forced nop executed here forced nop executed here pc pc + 1 pmadrh, pmadrl pc+3 pc + 5 flash addr rd bit instr (pc) pmdath, pmdatl instr (pc + 3) pc + 4 instr (pc + 4) instr (pc + 1) instr (pc - 1) executed here instr (pc + 3) executed here instr (pc + 4) executed here flash data pmdath pmdatl register force nop stop pc note: code-protect does not affect the cpu from performing a read operation on the program memory. for more information, refer to section 8.2 ?code protection? .
? 2010-2013 microchip technology inc. ds41430d-page 161 pic16(l)f720/721 18.5 writing to flash program memory a word of the flash program memory may only be written to if the word is in an unprotected segment of memory. flash program memory may only be written to if the destination address is in a segment of memory that is not write-protected, as defined in bits wrt<1:0> of the configuration word register 2. flash program memory must be written in 32-word rows. see figure 18-2 for more details. a row consists of 32 words with sequen- tial addresses, with a lower boundary defined by an address, where pmadr<4:0>= 00000. all row writes to program memory are done as 32-word erase and one to 32-word write operations. the write operation is edge-aligned. crossing boundaries is not recom- mended, as the operation will only affect the new boundary, wrapping the data values at the same time. once the write control bit is set, the program memory (pm) controller will immediately write the data. program execution is stalled while the write is in progress. to erase a program memory row, the address of the row to erase must be loaded into the pmadrh:pmadrl register pair. a row consists of 32 words so, when selecting a row, pmadr<4:0> are ignored. after the address has been set up, then the following sequence of events must be executed: 1. set the wren and free control bits of the pmcon1 register. 2. write 55h, then aah, to pmcon2 (flash programming sequence). 3. set the wr control bit of the pmcon1 register. to write program data, it must first be loaded into the buffer latches (see figure 18-2 ). this is accomplished by first writing the destination address to pmadrl and pmadrh and then writing the data to pmdata and pmdath. after the address and data have been set up, then the following sequence of events must be executed: 1. set the wren control bit of the pmcon1 register. 2. write 55h, then aah, to pmcon2 (flash programming sequence). 3. set the wr control bit of the pmcon1 register. all 32 buffer register locations should be written to with correct data. if less than 32 words are being written to in the block of 32 words, then a read from the program memory location(s) not being written to must be performed. this takes the data from the program location(s) not being written and loads it into the pmdatl and pmdath registers. then, the sequence of events to transfer data to the buffer registers must be executed. when the lwlo bit is ? 1 ?, the write sequence will only load the buffer register and will not actually initiate the write to program flash: 1. set the wren and lwlo bits of the pmcon1 register. 2. write 55h, then aah, to pmcon2 (flash programming unlock sequence). 3. set control bit wr of the pmcon1 register to begin the write operation. to transfer data from the buffer registers to the program memory, the last word to be written should be written to the pmdath:pmdatl register pair. then, the following sequence of events must be executed: 1. clear the lwlo bit of the pmcon1 register. 2. write 55h, then aah, to pmcon2 (flash programming sequence). 3. set control bit wr of the pmcon1 register to begin the write operation. 4. two nop must follow the setting of the wr bit. this is necessary to provide time for the address and to be provided to the program flash memory to be put in the write latches. no automatic erase occurs upon the initiation of the write; if the program flash needs to be erased before writing, the row (32 words) must be previously erased. after the ? bsf pmcon1 , wr ? instruction, the processor requires two cycles to set up the erase/write operation. the user must place two nop instructions after the wr bit is set. these two instructions will also be forced in hardware to nop , but if an icd break occurs at this point, the forcing to nop will be lost. note: self-write execution to flash memory cannot be done while running in low power pfm and voltage regulator modes. therefore, executing a self-write will put the pfm and voltage regulator into high power mode for the duration of the sequence. note: an icd break that occurs during the 55h - aah ? set wr bit sequence will interrupt the timing of the sequence and prevent the unlock sequence from occurring. in this case, no write will be initiated, as there was no operation to complete.
pic16(l)f720/721 ds41430d-page 162 ? 2010-2013 microchip technology inc. since data is being written to buffer registers, the writing of the first 31 words of the block appears to occur immediately. the processor will halt internal operations for the typical 2ms, only during the cycle in which the erase takes place (i.e., the last word of the 32-word block erase). this is not sleep mode as the clocks and peripherals will continue to run. after the 32- word write cycle, the processor will resume operation with the third instruction after the pmcon1 write instruction. figure 18-2: block of 32 writ es to flash program memory an example of the complete 32-word write sequence is shown in example 18-2 . the initial address is loaded into the pmadrh:pmadrl register pair; the 32 words of data are loaded using indirect addressing. 14 14 14 14 program memory buffer register pmadrl<4:0> = 00000 buffer register pmadrl<4:0> = 00001 buffer register pmadrl<4:0> = 00010 buffer register pmadrl<4:0> = 11111 pmdatl pmdath 75 07 0 6 8
? 2010-2013 microchip technology inc. ds41430d-page 163 pic16(l)f720/721 example 18-2: writing to flash program memory ; this write routine assumes the following: ; 1. a valid starting address (the least significant bits = ?00000?)is loaded in addrh:addrl ; 2. the 64 bytes of data are loaded, starting at the address in dataddr ; 3. addrh, addrl and dataddr are all located in shared data memory 0x70 - 0x7f ; banksel pmadrh ; bank 3 movf addrh,w ; load initial address movwf pmadrh ; movf addrl,w ; movwf pmadrl ; movf dataaddrl,w ; load initial data address movwf fsr0l ; movf dataaddrh,w ; load initial data address movwf fsr0h ; loop moviw indf0++ ; load first data byte into lower movwf pmdatl ; moviw indf0++ ; load second data byte into upper movwf pmdath ; bsf pmcon1,wren ; enable writes bsf pmcon1,lwlo ; only load write latches movlw 55h ; start of required write sequence: movwf pmcon2 ; write 55h movlw aah ; movwf pmcon2 ; write aah bsf pmcon1,wr ; set wr bit to begin write nop ; any instructions here are ignored as processor ; halts to begin write sequence nop ; processor will stop here and wait for write complete ; after write processor continues with 3rd instruction movf pmadr,w ; check if lower five bits of address are ?11111? xorlw 0x1f ; check if we?re on the last of 8 addresses andlw 0x1f ; btfsc status,z ; exit if last of 32 words, goto start_write ; incf pmadr,f ; still loading latches increment address goto loop ; write next latches start_write bcf pmcon1,lwlo ; no more latches only; actually start write movlw 55h ; start of required write sequence: movwf pmcon2 ; write 55h movlw aah ; movwf pmcon2 ; write aah bsf pmcon1,wr ; set wr bit to begin write nop ; any instructions here are ignored as processor ; halts to begin write sequence nop ; processor will stop here and wait for write complete ; after write processor continues with 3rd instruction bcf pmcon1,wren ; disable writes required sequence required sequence
pic16(l)f720/721 ds41430d-page 164 ? 2010-2013 microchip technology inc. 18.6 protection against spurious write there are conditions when the device should not write to the program memory. to protect against spurious writes, various mechanisms have been built in. on power-up, wren is cleared. also, the power-up timer (64 ms duration) prevents program memory writes. the write initiates sequence and the wren bit helps prevent an accidental write during brown-out, power glitch or software malfunction. 18.7 operation during code-protect when the device is code-protected, the cpu is able to read and write unscrambled data to the program memory. 18.8 operation during write-protect when the program memory is write-protected, the cpu can read and execute from the program memory. the portions of program memory that are write-protected can be modified by the cpu using the pmcon registers, but the protected program memory cannot be modified using icsp mode. register 18-1: pmcon1: progra m memory control 1 register u-1 r/w-0/0 r/w-0/0 r/w/hc-0/0 u-0 r/w-0/0 r/s/hc-0/0 r/s/hc-0/0 ?cfgslwlofree ?wrenwr rd bit 7 bit 0 legend: s = setable bit, cleared in hardware r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 1 ? bit 6 cfgs: flash program/configuration select bit 1 = accesses configuration, user id and device id registers 0 = accesses flash program bit 5 lwlo: load write latches only bit 1 = the next wr command does not initiate a write to the pfm; only the program memory latches are updated. 0 = the next wr command writes a value from pmdath:pmdatl into program memory latches and initiates a write to the pfm of all the data stored in the program memory latches. bit 4 free: program flash erase enable bit 1 = perform an program flash erase operation on the next wr command (cleared by hardware after completion of erase). 0 = perform a program flash write operation on the next wr command bit 3 unimplemented: read as ? 0 ? bit 2 wren: program/erase enable bit 1 = allows program/erase cycles 0 = inhibits programming/erasing of program flash bit 1 wr: write control bit 1 = initiates a program flash program/erase operation. the operation is self-timed and the bit is cleared by hardware once operation is complete. the wr bit can only be set (not cleared) in software. 0 = program/erase operation to the flash is complete and inactive bit 0 rd: read control bit 1 = initiates an program memory read (the rd is cleared in hardware; the rd bit can only be set (not cleared) in software). 0 = does not initiate a program memory read
? 2010-2013 microchip technology inc. ds41430d-page 165 pic16(l)f720/721 register 18-2: pmdath: program memory data high register u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? pmd13 pmd12 pmd11 pmd10 pmd9 pmd8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 pmd<13:8>: the value of the program memory word pointed to by pmadrh and pmadrl after a program memory read command. register 18-3: pmdatl: program memory data low register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x pmd7 pmd6 pmd5 pmd4 pmd3 pmd2 pmd1 pmd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 pmd<7:0>: the value of the program memory word pointed to by pmadrh and pmadrl after a program memory read command. register 18-4: pmadrh: program memory address high register u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? pma12 pma11 pma10 pma9 pma8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 pma<12:8>: program memory read address bits
pic16(l)f720/721 ds41430d-page 166 ? 2010-2013 microchip technology inc. register 18-5: pmadrl: program memory address low register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x pma7 pma6 pma5 pma4 pma3 pma2 pma1 pma0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 pma<7:0>: program memory read address bits table 18-1: summary of registers as sociated with program memory read name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page pmcon1 ? cfgs lwlo free ? wren wr rd 164 pmcon2 program memory control register 2 (not a physical register) ? pmadrh ? ? ? program memory read address register high byte 165 pmadrl program memory read address register low byte 166 pmdath ? ? program memory read data register high byte 165 pmdatl program memory read data register low byte 165 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the program memory read.
? 2010-2013 microchip technology inc. ds41430d-page 167 pic16(l)f720/721 19.0 power-down mode (sleep) the power-down mode is entered by executing a sleep instruction. if the watchdog timer is enabled: ? wdt will be cleared but keeps running. ?pd bit of the status register is cleared. ?to bit of the status register is set. ? oscillator driver is turned off. ? i/o ports maintain the status they had before sleep was executed (driving high, low or high- impedance). for lowest current consumption in this mode, all i/o pins should be either at v dd or v ss , with no external circuitry drawing current from the i/o pin. i/o pins that are high-impedance inputs should be pulled high or low externally to avoid switching currents caused by float- ing inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on-chip pull-ups on portb should be considered. the mclr pin must be at a logic high level when external mclr is enabled. 19.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from ra2/int pin, portb change or a peripheral interrupt. the first event will cause a device reset. the two latter events are considered a continuation of program execution. the to and pd bits in the status register can be used to determine the cause of a device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. to bit is cleared if wdt wake-up occurred. the following peripheral interrupts can wake the device from sleep: 1. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 2. usart receive interrupt (synchronous slave mode only) 3. a/d conversion (when a/d clock source is rc) 4. interrupt-on-change 5. external interrupt from int pin 6. capture event on ccp1 7. ssp interrupt in spi or i 2 c slave mode other peripherals cannot generate interrupts since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is prefetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction, then branches to the interrupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. the wdt is cleared when the device wakes up from sleep, regardless of the source of wake-up. note: a reset generated by a wdt time-out does not drive mclr pin low. note: if the global interrupts are disabled (gie is cleared), but any interrupt source has both its interrupt enable bit and the correspond- ing interrupt flag bits set, the device will immediately wake-up from sleep. the sleep instruction is completely executed.
pic16(l)f720/721 ds41430d-page 168 ? 2010-2013 microchip technology inc. 19.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur: ? if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will complete as a nop . therefore, the wdt and wdt prescaler and postscaler (if enabled) will not be cleared, the to bit will not be set and the pd bit will not be cleared. ? if the interrupt occurs during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt prescaler and postscaler (if enabled) will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction. figure 19-1: wake-up from sleep through interrupt q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 oscillator clkout (2) int pin intf flag (intcon reg.) gie bit (intcon reg.) instruction flow pc instruction fetched instruction executed pc pc + 1 pc + 2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency (1) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle pc + 2 note 1: gie = 1 assumed. in this case after wake-up, the processor jumps to 0004h. if gie = 0 , execution will continue in-line. 2: clkout is not available in ec oscillator mode, but shown here for timing reference. table 19-1: summary of registers associated with power-down mode name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 register on page iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ? 56 intcon gie peie tmr0ie inte rabie tmr0if intf rabif 38 pie1 tmr1gie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 39 pir1 tmr1gif adif rcif txif sspif ccp1if tmr2if tmr1if 40 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used in power-down mode.
? 2010-2013 microchip technology inc. ds41430d-page 169 pic16(l)f720/721 20.0 in-circuit serial programming? (icsp?) icsp? programming allows customers to manufacture circuit boards with unprogrammed devices. programming can be done after the assembly process, allowing the device to be programmed with the most recent firmware or a custom firmware. five pins are needed for icsp? programming: ? icspclk ? icspdat ?mclr /v pp ?v dd ?v ss the device is placed into program/verify mode by holding the icspclk and icspdat pins low then raising the voltage on mclr /v pp from 0v to v pp . in program/verify mode the program memory, user ids and the configuration words are programmed through serial communications. the icspdat pin is a bidirectional i/o used for transferring the serial data and the iscpclk pin is the clock input. for more information on icsp? refer to the ? pic16f72x/pic16lf72x programming specification? (ds41332). figure 20-1: typical connect ion for icsp? programming v dd v pp gnd external device to be data clock v dd mclr /v pp v ss icspdat icspclk * * * to normal connections * isolation devices (as required). 10k programming signals programmed v dd
pic16(l)f720/721 ds41430d-page 170 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 171 pic16(l)f720/721 21.0 instruction set summary the pic16(l)f720/721 instruction set is highly orthogonal and is comprised of three basic categories: ? byte-oriented operations ? bit-oriented operations ? literal and control operations each pic16 instruction is a 14-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the formats for each of the categories is presented in figure 21-1 , while the various opcode fields are summarized in tab l e 2 1- 1 . table 21-2 lists the instructions recognized by the mpasm tm assembler. for byte-oriented instructions, ?f? represents a file register designator and ?d? represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the w register. if ?d? is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, ?b? represents a bit field designator, which selects the bit affected by the operation, while ?f? represents the address of the file in which the bit is located. for literal and control operations, ?k? represents an 8- bit or 11-bit constant, or literal value. one instruction cycle consists of four oscillator periods; for an oscillator frequency of 4 mhz, this gives a nominal instruction execution time of 1 ? s. all instructions are executed within a single instruction cycle, unless a conditional test is true, or the program counter is changed as a result of an instruction. when this occurs, the execution takes two instruction cycles, with the second cycle executed as a nop . all instruction examples use the format ? 0xhh ? to represent a hexadecimal number, where ? h ? signifies a hexadecimal digit. 21.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (r-m-w) operation. the register is read, the data is modified, and the result is stored according to either the instruc- tion, or the destination designator ?d?. a read operation is performed on a register even if the instruction writes to that register. for example, a clrf portb instruction will read portb, clear all the data bits, then write the result back to portb. this example would have the unin- tended consequence of clearing the condition that set the rabif flag. figure 21-1: general format for instructions table 21-1: opcode field descriptions field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don?t care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w , d = 1 : store result in file register f. default is d = 1. pc program counter to time-out bit c carry bit dc digit carry bit z zero bit pd power-down bit byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
pic16(l)f720/721 ds41430d-page 172 ? 2010-2013 microchip technology inc. table 21-2: pic16(l)f720/721 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f ? f, d f, d f, d f, d f, d f, d f, d f ? f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1 (2) 1 1 (2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c, dc, z z z z z z z z z c c c, dc, z z 1, 2 1, 2 2 1, 2 1, 2 1, 2, 3 1, 2 1, 2, 3 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1, 2 1, 2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k ? k k k ? k ? ? k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c, dc, z z to , pd z to , pd c, dc, z z note 1: when an i/o register is modified as a function of itself (e.g., movf porta, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tm r0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if the program counter (pc) is modified, or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop .
? 2010-2013 microchip technology inc. ds41430d-page 173 pic16(l)f720/721 21.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 ? k ? 255 operation: (w) + k ? (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal ?k? and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 ? f ? 127 d ??? 0 , 1 ? operation: (w) + (f) ? (destination) status affected: c, dc, z description: add the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. andlw and literal with w syntax: [ label ] andlw k operands: 0 ? k ? 255 operation: (w) .and. (k) ? (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal ?k?. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 ? f ? 127 d ??? 0 , 1 ? operation: (w) .and. (f) ? (destination) status affected: z description: and the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 ? f ? 127 0 ? b ? 7 operation: 0 ? (f) status affected: none description: bit ?b? in register ?f? is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 ? f ? 127 0 ? b ? 7 operation: 1 ? (f) status affected: none description: bit ?b? in register ?f? is set. btfsc bit test f, skip if clear syntax: [ label ] btfsc f,b operands: 0 ? f ? 127 0 ? b ? 7 operation: skip if (f) = 0 status affected: none description: if bit ?b? in register ?f? is ? 1 ?, the next instruction is executed. if bit ?b? in register ?f? is ? 0 ? the next instruction is discarded and a nop is executed instead, making this a 2-cycle instruction.
pic16(l)f720/721 ds41430d-page 174 ? 2010-2013 microchip technology inc. btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 ? f ? 127 0 ? b < 7 operation: skip if (f) = 1 status affected: none description: if bit ?b? in register ?f? is ? 0 ?, the next instruction is executed. if bit ?b? is ? 1 ?, then the next instruction is discarded and a nop is executed instead, making this a 2-cycle instruction. call call subroutine syntax: [ label ] call k operands: 0 ? k ? 2047 operation: (pc)+ 1 ? tos, k ? pc<10:0>, (pclath<4:3>) ? pc<12:11> status affected: none description: call subroutine. first, return address (pc + 1) is pushed onto the stack. the eleven-bit immediate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 ? f ? 127 operation: 00h ? (f) 1 ? z status affected: z description: the contents of register ?f? are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h ? (w) 1 ? z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h ? wdt 0 ? wdt prescaler, 1 ? to 1 ? pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. comf complement f syntax: [ label ] comf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f ) ? (destination) status affected: z description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. decf decrement f syntax: [ label ] decf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f) - 1 ? (destination) status affected: z description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
? 2010-2013 microchip technology inc. ds41430d-page 175 pic16(l)f720/721 decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f) - 1 ? (destination); skip if result = 0 status affected: none description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, then a nop is executed instead, making it a 2-cycle instruction. goto unconditional branch syntax: [ label ] goto k operands: 0 ? k ? 2047 operation: k ? pc<10:0> pclath<4:3> ? pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f) + 1 ? (destination) status affected: z description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f) + 1 ? (destination), skip if result = 0 status affected: none description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, a nop is executed instead, making it a 2-cycle instruction. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 ? k ? 255 operation: (w) .or. k ? (w) status affected: z description: the contents of the w register are or?ed with the eight-bit literal ?k?. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (w) .or. (f) ? (destination) status affected: z description: inclusive or the w register with register ?f?. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?.
pic16(l)f720/721 ds41430d-page 176 ? 2010-2013 microchip technology inc. movf move f syntax: [ label ] movf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f) ? (dest) status affected: z description: the contents of register f is moved to a destination dependent upon the status of d. if d = 0 , destination is w register. if d = 1 , the destination is file register f itself. d = 1 is useful to test a file register since status flag z is affected. words: 1 cycles: 1 example: movf fsr, 0 after instruction w= value in fsr register z= 1 movlw move literal to w syntax: [ label ] movlw k operands: 0 ? k ? 255 operation: k ? (w) status affected: none description: the eight-bit literal ?k? is loaded into w register. the ?don?t cares? will assemble as ? 0 ?s. words: 1 cycles: 1 example: movlw 0x5a after instruction w= 0x5a movwf move w to f syntax: [ label ] movwf f operands: 0 ? f ? 127 operation: (w) ? (f) status affected: none description: move data from w register to register ?f?. words: 1 cycles: 1 example: movw f option before instruction option = 0xff w = 0x4f after instruction option = 0x4f w = 0x4f nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none description: no operation. words: 1 cycles: 1 example: nop
? 2010-2013 microchip technology inc. ds41430d-page 177 pic16(l)f720/721 retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos ? pc, 1 ? gie status affected: none description: return from interrupt. stack is poped and top-of-stack (tos) is loaded in the pc. interrupts are enabled by setting global interrupt enable bit, gie (intcon<7>). this is a two-cycle instruction. words: 1 cycles: 2 example: retfie after interrupt pc = tos gie = 1 retlw return with literal in w syntax: [ label ] retlw k operands: 0 ? k ? 255 operation: k ? (w); tos ? pc status affected: none description: the w register is loaded with the eight bit literal ?k?. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. words: 1 cycles: 2 example: table call table;w contains table ;offset value ? ;w now has table value ? ? addwf pc ;w = offset retlw k1 ;begin table retlw k2 ; ? ? ? retlw kn ; end of table before instruction w = 0x07 after instruction w = value of k8 return return from subroutine syntax: [ label ] return operands: none operation: tos ? pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction.
pic16(l)f720/721 ds41430d-page 178 ? 2010-2013 microchip technology inc. rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. words: 1 cycles: 1 example: rlf reg1,0 before instruction reg1 = 1110 0110 c=0 after instruction reg1 = 1110 0110 w = 1100 1100 c=1 rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. register f c register f c sleep enter sleep mode syntax: [ label ] sleep operands: none operation: 00h ? wdt, 0 ? wdt prescaler, 1 ? to , 0 ? pd status affected: to , pd description: the power-down status bit, pd is cleared. time-out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 ?? k ?? 255 operation: k - (w) ??? w) status affected: c, dc, z description: the w register is subtracted (2?s complement method) from the eight-bit literal ?k?. the result is placed in the w register. c = 0 w ? k c = 1 w ? k dc = 0 w<3:0> ? k<3:0> dc = 1 w<3:0> ? k<3:0>
? 2010-2013 microchip technology inc. ds41430d-page 179 pic16(l)f720/721 subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 ?? f ?? 127 d ? [ 0 , 1 ] operation: (f) - (w) ??? destination) status affected: c, dc, z description: subtract (2?s complement method) w register from register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (f<3:0>) ? (destination<7:4>), (f<7:4>) ? (destination<3:0>) status affected: none description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed in register ?f?. c = 0 w ? f c = 1 w ? f dc = 0 w<3:0> ? f<3:0> dc = 1 w<3:0> ? f<3:0> xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 ?? k ?? 255 operation: (w) .xor. k ??? w) status affected: z description: the contents of the w register are xor?ed with the eight-bit literal ?k?. the result is placed in the w register. xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 ? f ? 127 d ? [ 0 , 1 ] operation: (w) .xor. (f) ??? destination) status affected: z description: exclusive or the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
pic16(l)f720/721 ds41430d-page 180 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 181 pic16(l)f720/721 22.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: ? integrated development environment - mplab ? ide software ? compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c ? for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families ? simulators - mplab sim software simulator ?emulators - mplab real ice? in-circuit emulator ? in-circuit debuggers - mplab icd 3 - pickit? 3 debug express ? device programmers - pickit? 2 programmer - mplab pm3 device programmer ? low-cost demonstration/development boards, evaluation kits, and starter kits 22.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as iar c compilers the mplab ide allows you to: ? edit your source files (either c or assembly) ? one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) ? debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic16(l)f720/721 ds41430d-page 182 ? 2010-2013 microchip technology inc. 22.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchip?s pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 22.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchip?s pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 22.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 22.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 22.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire device instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility
? 2010-2013 microchip technology inc. ds41430d-page 183 pic16(l)f720/721 22.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 22.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 22.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 22.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software.
pic16(l)f720/721 ds41430d-page 184 ? 2010-2013 microchip technology inc. 22.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchip?s flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchip?s powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software. 22.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 22.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page ( www.microchip.com ) for the complete list of demonstration, development and evaluation kits.
? 2010-2013 microchip technology inc. ds41430d-page 185 pic16(l)f720/721 23.0 electrical specifications absolute maximum ratings (?) ambient temperature under bias................................................................................................. ...... -40c to +125c storage temperature ............................................................................................................ ............ -65c to +150c voltage on v dd with respect to v ss , pic16f720/721 ........................................................................ -0.3v to +6.5v voltage on v dd with respect to v ss , pic16lf720/721 ...................................................................... -0.3v to +4.0v voltage on mclr with respect to v ss ................................................................................................. -0.3v to +9.0v voltage on all other pins with respect to v ss ........................................................................... -0.3v to (v dd + 0.3v) total power dissipation (1) ............................................................................................................................... 800 mw maximum current out of v ss pin ...................................................................................................................... 95 m a maximum current into v dd pin ......................................................................................................................... 7 0 ma clamp current, i k (v pin < 0 or v pin > v dd ) ??????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????? 20 ma maximum output current sunk by any i/o pin..................................................................................... ............... 25 ma maximum output current sourced by any i/o pin .................................................................................. ............ 25 ma maximum current sunk by all ports, -40c ? t a ? +85c for industrial............................................................ 200 ma maximum current sunk by all ports, -40c ? t a ? +125c for extended ........................................................... 90 ma maximum current sourced by all ports, 40c ? t a ? +85c for industrial....................................................... 140 ma maximum current sourced by all ports, -40c ? t a ? +125c for extended ...................................................... 65 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd ? ? i oh } + ? {(v dd ? v oh ) x i oh } + ? (v o l x i ol ). ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure above maximum rating conditions for extended periods may affect device reliability.
pic16(l)f720/721 ds41430d-page 186 ? 2010-2013 microchip technology inc. 23.1 dc characteristics: pic16(l)f720/721-i/e (industrial, extended) pic16lf720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended pic16f720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param. no. sym. characteristic min. typ? max. units conditions d001 v dd supply voltage pic16lf720/721 1.8 ? 3.6 v f osc ? 16 mhz: hfintosc, ec d001 pic16f720/721 1.8 ? 5.5 v f osc ? 16 mhz: hfintosc, ec d002* v dr ram data retention voltage (1) pic16lf720/721 1.5 ? ? v device in sleep mode d002* pic16f720/721 1.7 ? ? v device in sleep mode v por * power-on reset release voltage ?1.6? v v porr * power-on reset rearm voltage pic16lf720/721 ?0.9? v pic16f720/721 ? 1.5 ? v d003 v fvr fixed voltage reference voltage, initial accuracy -8 ? 6 % v fvr = 1.024v, v dd ? 2.5v v fvr = 2.048v, v dd ? 2.5v v fvr = 4.096v, v dd ?? 4.75v; d004* s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 3.2 ?power-on reset (por)? for details. * these parameters are characterized but not tested. ? data in ?typ? column is at 3.3v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered in sleep mode without losing ram data.
? 2010-2013 microchip technology inc. ds41430d-page 187 pic16(l)f720/721 figure 23-1: por and por rearm with slow rising v dd v dd v por v porr v ss v ss npor t por (3) por rearm note 1: when npor is low, the device is held in reset. 2: t por 1 ? s typical. 3: t vlow 2.7 ? s typical. t vlow (2)
pic16(l)f720/721 ds41430d-page 188 ? 2010-2013 microchip technology inc. 23.2 dc characteristics: pic16(l)f720/721-i/e (industrial, extended) pic16lf720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended pic16f720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param. no. device characteristics min. typ? max. units conditions v dd note supply current (i dd ) (1, 2) d013 ? 100 180 ? a1.8f osc = 1 mhz ec mode ? 210 270 ? a3.0 d013 ? 120 205 ? a 1.8 f osc = 1 mhz ec mode ? 220 320 ? a 3.0 ? 250 410 ? a 5.0 d014 ? 220 330 ? a1.8f osc = 4 mhz ec mode ? 420 500 ? a3.0 d014 ? 250 430 ? a 1.8 f osc = 4 mhz ec mode ? 450 655 ? a 3.0 ? 500 730 ? a 5.0 d015 ? 105 203 ? a1.8f osc = 500 khz mfintosc mode ? 130 235 ? a3.0 d015 ? 120 219 ? a 1.8 f osc = 500 khz mfintosc mode ? 145 284 ? a 3.0 ? 160 348 ? a 5.0 d016 ? 600 800 ? a1.8f osc = 8 mhz hfintosc mode ? 1000 1200 ? a3.0 d016 ? 610 850 ? a 1.8 f osc = 8 mhz hfintosc mode ? 1010 1200 ? a 3.0 ? 1150 1500 ? a 5.0 d017 ? 900 1200 ? a1.8f osc = 16 mhz hfintosc mode ? 1450 1850 ? a3.0 d017 ? 910 1200 ? a 1.8 f osc = 16 mhz hfintosc mode ? 1460 1900 ? a 3.0 ? 1700 2100 ? a 5.0 note 1: the test conditions for all i dd measurements in active ec mode are: clkin = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pa ttern and temperature, also have an impact on the current consumption.
? 2010-2013 microchip technology inc. ds41430d-page 189 pic16(l)f720/721 23.3 dc characteristics: pic16(l)f720/721-i/e (power-down) pic16lf720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended pic16f720/721 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param. no. device characteristics min. typ? max. +85c max. +125c units conditions v dd note power-down base current (i pd ) (2) d020 ? 0.04 1 8 ? a 1.8 base i pd ?0.05 2 9 ? a3.0 d020 ? 18 47 55 ? a 1.8 base i pd ? 20 58 72 ? a 3.0 ? 23 60 84 ? a 5.0 d021 ? 0.5 4 9 ? a1.8i pd lpwdt on (note 1) ?0.8 5 11 ? a3.0 d021 ? 20 49 57 ? a 1.8 i pd lpwdt on (note 1) ? 22 60 74 ? a 3.0 ? 25 63 86 ? a 5.0 d021a ? 14 29 35 ? a1.8i pd fvr on (note 1) ?15 31 38 ? a3.0 d021a ? 39 77 90 ? a 1.8 i pd fvr on (note 1) ? 46 98 108 ? a 3.0 ? 91 160 170 ? a 5.0 d022 ? ? ? ? ? a1.8i pd bor on (note 1) ? 7 15 26 ? a3.0 d022 ? ? ? ? ? a 1.8 i pd bor on (note 1) ? 26 64 78 ? a 3.0 ? 29 67 91 ? a 5.0 d027 ? 1.5 4 10 ? a1.8i pd adc on (note 1, note 3) non-convert ?2 5 11 ? a3.0 d027 ? 19 48 57 ? a 1.8 i pd adc on (note 1, note 3) non-convert ? 21 59 74 ? a 3.0 ? 24 62 87 ? a 5.0 d027a ? 250 400 410 ? a1.8i pd adc on (note 1, note 3) convert ? 260 420 430 ? a3.0 d027a ? 280 430 440 ? a 1.8 i pd adc on (note 1, note 3) convert ? 300 450 460 ? a 3.0 ? 320 470 480 ? a 5.0 ? data in ?typ? column is at 3.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral ? current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 2: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd . 3: a/d oscillator source is f rc .
pic16(l)f720/721 ds41430d-page 190 ? 2010-2013 microchip technology inc. 23.4 dc characteristics: pic16(l)f720/721-i/e dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param. no. sym. characteristic min. typ? max. units conditions v il input low voltage i/o port: d030 with ttl buffer ? ? 0.8 v 4.5v ? v dd ? 5.5v d030a ? ? 0.15 v dd v1.8v ? v dd ? 4.5v d031 with schmitt trigger buffer ? ? 0.2 v dd v2.0v ? v dd ? 5.5v with i 2 c? levels ? ? 0.3 v dd v v ih input high voltage i/o ports: ? ? d040 with ttl buffer 2.0 ? ? v 4.5v ? v dd ?? 5.5v d040a 0.25 v dd + 0.8 ??v1.8v ? v dd ? 4.5v d041 with schmitt trigger buffer 0.8 v dd ??v2.0v ? v dd ? 5.5v with i 2 c? levels 0.7 v dd ??v d042 mclr 0.8 v dd ??v i il input leakage current (1) d060 i/o ports ? 5 5 125 1000 na na v ss ? v pin ? v dd , pin at high- impedance, 85c 125c d061 mclr (2) ? 50 200 na v ss ? v pin ? v dd , 85c i pur portb weak pull-up current d070* 25 25 100 140 200 300 ? a v dd = 3.3v, v pin = v ss v dd = 5.0v, v pin = v ss v ol output low voltage d080 i/o ports ??0.6v i ol = 8ma, v dd = 5v i ol = 6ma, v dd = 3.3v i ol = 1.8ma, v dd = 1.8v v oh output high voltage d090 i/o ports v dd - 0.7 ? ? v i oh = 3.5ma, v dd = 5v i oh = 3ma, v dd = 3.3v i oh = 1ma, v dd = 1.8v c io capacitive loading specs on output pins d101a* all i/o pins ? ? 50 pf e p program flash memory d130 cell endurance 1k 10k ? e/w tem perature during programming: 10c ? t a ? 40c d131 v pr v dd for read v min ??v v ihh voltage on mclr /v pp during erase/program 8.0 ? 9.0 v temperature during programming: 10c ? t a ? 40c d132 v pew v dd for write or row erase 1.8 1.8 ? ? 5.5 3.6 v v pic16f720/721 pic16lf720/721 i pppgm * current on mclr /v pp during erase/write ?1.0?ma temperature during programming: 10c ? t a ? 40c i ddpgm * current on v dd during erase/ write ?5.0 ?ma temperature during programming: 10c ? t a ? 40c * these parameters are characterized but not tested. ? data in ?typ? column is at 3.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: negative current is defined as current sourced by the pin. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages.
? 2010-2013 microchip technology inc. ds41430d-page 191 pic16(l)f720/721 d133 t pew erase/write cycle time ? 2.8 ms temperature during programming: 10c ? t a ? 40c d134* t retd characteristic retention ? 40 ? year provided no other specifications are violated d135 e hefc high-endurance flash cell 100k ? ? e/w 0c to +60c lower byte, last 128 addresses in flash memory 23.4 dc characteristics: pic16(l)f720/721-i/e (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param. no. sym. characteristic min. typ? max. units conditions * these parameters are char acterized but not tested. ? data in ?typ? column is at 3.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: negative current is defined as current sourced by the pin. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages.
pic16(l)f720/721 ds41430d-page 192 ? 2010-2013 microchip technology inc. 23.5 thermal considerations standard operating conditions (unless otherwise stated) operating temperature-40c ? t a ? +125c param. no. sym. characteristic typ. units conditions th01 ? ja thermal resistance junction to ambient 62.2 ? c/w 20-pin pdip package 75.0 ? c/w 20-pin soic package 89.3 ? c/w 20-pin ssop package 43.0 ? c/w 20-pin qfn 4x4mm package th02 ? jc thermal resistance junction to case 27.5 ? c/w 20-pin pdip package 23.1 ? c/w 20-pin soic package 31.1 ? c/w 20-pin ssop package 5.3 ? c/w 20-pin qfn 4x4mm package th03 t jmax maximum junction temperature 150 ? c th04 pd power dissipation ? w pd = p internal + p i / o th05 p internal internal power dissipation ? w p internal = i dd x v dd (1) th06 p i / o i/o power dissipation ? w p i / o = ? (i ol * v ol ) + ? (i oh * (v dd - v oh )) th07 p der derated power ? w p der = pd max (t j - t a )/ ? ja (2) note 1: i dd is current to run the chip alone without driving any load on the output pins. 2: t a = ambient temperature; t j = junction temperature
? 2010-2013 microchip technology inc. ds41430d-page 193 pic16(l)f720/721 23.6 timing parameter symbology the timing parameter symbols have been created with one of the following formats: figure 23-2: load conditions 1. tpps2pps 2. tpps t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc clkin ck clkout rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (high-impedance) v valid l low z high-impedance v ss c l legend: c l = 50 pf for all pins load condition pin
pic16(l)f720/721 ds41430d-page 194 ? 2010-2013 microchip technology inc. 23.7 ac characteristics: pic16f720/721-i/e figure 23-3: pic16f720/721 voltage frequency graph, -40c ? t a ?? +125c figure 23-4: pic16lf720/721 vo ltage frequency graph, -40c ? t a ?? +125c 1.8 0 frequency (mhz) v dd (v) note 1: the shaded region indicates the permissible combinations of voltage and frequency. 8 5.5 16 1.8 0 frequency (mhz) v dd (v) note 1: the shaded region indicates the permissible combinations of voltage and frequency. 8 3.6 16
? 2010-2013 microchip technology inc. ds41430d-page 195 pic16(l)f720/721 figure 23-5: hfintosc frequency accuracy over device v dd and temperature 125 25 2.0 0 60 85 v dd (v) 4.0 5.0 4.5 temperature (c) 2.5 3.0 3.5 5.5 1.8 -40 5% 2% 5% 3%
pic16(l)f720/721 ds41430d-page 196 ? 2010-2013 microchip technology inc. figure 23-6: clock timing clkin clkout q4 q1 q2 q3 q4 q1 os02 os03 table 23-1: clock oscillator timing requirements standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +125c param. no. sym. characteristic min. typ? max. units conditions os01 f osc external clkin frequency (1) dc ? 16 mhz ec oscillator mode os02 t osc external clkin period (1) 63 ? ? ns ec oscillator mode os03 t cy instruction cycle time (1) 250 t cy dc ns t cy = 4/f osc * these parameters are characterized but not tested. ? data in ?typ? column is at 3.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time bas e period. all specified values are based on characterization data for that particular oscillator ty pe under standard operating conditions with the device executing code. exceeding these specified limits may result in an uns table oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min? va lues with an external clock applied to clkin pin. when an external clock input is used, the ?max? cycle ti me limit is ?dc? (no clock) for all devices.
? 2010-2013 microchip technology inc. ds41430d-page 197 pic16(l)f720/721 table 23-2: oscillator parameters (1) standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. sym characteristic freq. tolerance min. typ? max. units conditions os08 hf osc internal calibrated hfintosc frequency (2, 3) ?? 2% ? 16.0 ? mhz 0c ? t a ? +60c, v dd ?? 2.5v ?? 3% ? 16.0 ? mhz +60c ? t a ? +85c, v dd ?? 2.5v ?? 5% ? 16.0 ? mhz -40c ? t a ? +125c os08 mf osc internal calibrated mfintosc frequency (2, 3) ?? 2% ? 500 ? khz 0c ? t a ? +60c, v dd ?? 2.5v ?? 3% ? 500 ? khz +60c ? t a ? +85c, v dd ?? 2.5v ?? 5% ? 500 ? khz -40c ? t a ? +125c os10* t iosc st hfintosc 16 mhz and mfintosc 500 khz oscillator wake-up from sleep start-up time ??58 ? s * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to the clkin pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. 2: to ensure these oscillator frequency tolerances, v dd and v ss must be capacitively decoupled as close to the device as possible. 0.1 ? f and 0.01 ? f values in parallel are recommended. 3: the frequency tolerance of the internal oscillator is 2% from 0-60c and 3% from 60-85c (see figure 23-5 ).
pic16(l)f720/721 ds41430d-page 198 ? 2010-2013 microchip technology inc. figure 23-7: clkout and i/o timing f osc clkout i/o pin (input) i/o pin (output) q4 q1 q2 q3 os11 os19 os13 os15 os18, os19 os20 os21 os17 os16 os14 os12 os18 old value new value write fetch read execute cycle table 23-3: clkout and i/o timing parameters standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. sym. characteristic min. typ? max. units conditions os11* t os h2 ck lf osc ? to clkout ? (1) ? ? 70 ns v dd = 3.3-5.0v os12* t os h2 ck hf osc ? to clkout ? (1) ? ? 72 ns v dd = 3.3-5.0v os13* t ck l2 io vclkout ? to port out valid (1) ? ? 20 ns os14* t io v2 ck h port input valid before clkout ? (1) t osc + 200 ns ? ? ns os15* t os h2 io vf osc ? (q1 cycle) to port out valid ? 50 70* ns v dd = 3.3-5.0v os16* t os h2 io if osc ? (q2 cycle) to port input invalid (i/o in hold time) 50 ? ? ns v dd = 3.3-5.0v os17* t io v2 os h port input valid to f osc ?? (q2 cycle) (i/o in setup time) 20 ? ? ns os18* t io r port output rise time ? ? 15 40 32 72 ns v dd = 2.0v v dd = 3.3-5.0v os19* t io f port output fall time ? ? 28 15 55 30 ns v dd = 2.0v v dd = 3.3-5.0v os20* t inp int pin input high or low time 25 ? ? ns os21* t rbp portb interrupt-on-change new input level time t cy ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 3.0v, 25 ? c unless otherwise stated. note 1: measurements are taken in ec mode where clkout output is 4 x t osc .
? 2010-2013 microchip technology inc. ds41430d-page 199 pic16(l)f720/721 figure 23-8: brown-out rese t timing and characteristics v bor v dd (device in brown-out reset) (device not in brown-out reset) t pwrt (1) note 1: the additional delay of t pwrt , prior to releasing reset, only occurs when the power-up timer is enabled (p wrte = 0 ). reset (due to bor) v bor + v hyst t bordc
pic16(l)f720/721 ds41430d-page 200 ? 2010-2013 microchip technology inc. table 23-4: reset, watchdog time, power-up timer, and brown-out reset parameters figure 23-9: timer0 and time r1 external clock timings standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. sym. characteristic min. typ? max. units conditions 30* t mc lmclr pulse width (low) 2 5 ? ? ? ? ? s ? s v dd = 5v, -40c to +85c v dd = 5v (1) 31 t wdt standard watchdog timer time-out period (no prescaler) (2) 10 10 18 18 27 33 ms ms v dd = 3.3v-5v, -40c to +85c v dd = 3.3v-5v (1) 33* t pwrt power-up timer period, pwrte = 0 40 65 140 ms 34* t ioz i/o high-impedance from mclr low or watchdog timer reset ??2.0 ? s 35 v bor brown-out reset voltage 1.80 1.9 2.1 v 36* v hyst brown-out reset hysteresis 0 25 50 mv 37* t bordc brown-out reset dc response time 135 10 ? sv dd ? v bor , -40c to +85c v dd ? v bor * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: voltages above 3.6v require that the regulator be enabled. 2: design target. if unable to meet this target, the maximum can be increased, but the minimum cannot be changed. t0cki t1cki 40 41 42 45 46 47 49 tmr0 or tmr1
? 2010-2013 microchip technology inc. ds41430d-page 201 pic16(l)f720/721 figure 23-10: capture/com pare/pwm timings (ccp) table 23-5: timer0 and timer1 external clock requirements standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. sym. characteristic min. typ? max. units conditions 40* t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 41* t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 42* t t 0p t0cki period greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4, ..., 256) 45* t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 15 ? ? ns asynchronous 30 ? ? ns 46* t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 15 ? ? ns asynchronous 30 ? ? ns 47* t t 1p t1cki input period synchronous greater of: 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) asynchronous 60 ? ? ns 49* tckez tmr 1 delay from external clock edge to timer increment 2 t osc ?7 t osc ? timers in sync mode * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 23-2 for load conditions. (capture mode) cc01 cc02 cc03 ccp
pic16(l)f720/721 ds41430d-page 202 ? 2010-2013 microchip technology inc. table 23-6: capture/compare/pwm requirements (ccp) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +125c param. no. sym. characteristic min. typ? max. units conditions cc01* tccl ccp input low time no prescaler 0.5t cy + 20 ? ? ns with prescaler 20 ? ? ns cc02* tcch ccp input high time no prescaler 0.5t cy + 20 ? ? ns with prescaler 20 ? ? ns cc03* tccp ccp input period 3t cy + 40 n ? ? ns n = prescale value (1, 4 or 16) * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. table 23-7: pic16f720/721 a/d converter (adc) characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +125c param. no. sym. characteristic min. typ? max. units conditions ad01 n r resolution ? ? 8 bit ad02 e il integral error ? ? 1.0 lsb v dd = 3.0v ad03 e dl differential error ? ? 1 lsb no missing codes v dd = 3.0v ad04 e off offset error ? ? 2.0 lsb v dd = 3.0v ad07 e gn gain error ? ? 1.5 lsb v dd = 3.0v ad07 v ain full-scale range v ss ?v dd v ad08* z ain recommended impedance of analog voltage source ?? 10k ? can go higher if external 0.01 ? f capacitor is present on input pin. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested.
? 2010-2013 microchip technology inc. ds41430d-page 203 pic16(l)f720/721 figure 23-11: pic16f720/721 a/d co nversion timing (normal mode) table 23-8: pic16f720/721 a/d conversion requirements standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +125c param. no. sym. characteristic min. typ? max. units conditions ad130* t ad a/d clock period 1.0 ? 9.0 ? sv dd ? 2.0v (2) 4.0 ? 16.0 ? sv dd ? 2.0v (2) a/d internal rc oscillator period 1.0 2.0 6.0 ? s (adrc mode) ad131 t cnv conversion time (not including acquisition time) (1) ? 10.5 ? t ad set go/done bit to new data in a/d result register ad132* t acq acquisition time 2 ? ? sv dd = 3.0v, ec or intosc clock mode (3) * these parameters are char acterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the adres register may be read on the following t cy cycle. 2: setting of 16.0 ? s t ad not recommended for temperature > 85c. 3: if adrc mode is selected for use with v dd ?? 2.0v, longer acquisition times will be required (see section 9.3 ?a/d acquisition requirements? ) ad131 ad130 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data 765 3210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy 4 ad134 (t osc /2 (1) ) 1 t cy ad132
pic16(l)f720/721 ds41430d-page 204 ? 2010-2013 microchip technology inc. figure 23-12: pic16f720/721 a/d conversion timing (sleep mode) figure 23-13: usart synchronous transmission (master/slave) timing ad132 ad131 ad130 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data 7 5 3210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. ad134 4 6 1 t cy (t osc /2 + t cy (1) ) 1 t cy note: refer to figure 23-2 for load conditions. us121 us121 us120 us122 ck dt table 23-9: usart synchronous transmission requirements standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. symbol characteristic min. max. units conditions us120* t ck h2 dt v sync xmit (m aster and s lave ) clock high to data-out valid 3.0-5.5v ? 80 ns 1.8-5.5v ? 100 ns us121* t ckrf clock out rise time and fall time (master mode) 3.0-5.5v ? 45 ns 1.8-5.5v ? 50 ns us122* t dtrf data-out rise time and fall time 3.0-5.5v ? 45 ns 1.8-5.5v ? 50 ns * these parameters are characterized but not tested.
? 2010-2013 microchip technology inc. ds41430d-page 205 pic16(l)f720/721 figure 23-14: usart synchrono us receive (master/slave) timing figure 23-15: spi master mode timing (cke = 0 , smp = 0 ) note: refer to figure 23-2 for load conditions. us125 us126 ck dt table 23-10: usart synchrono us receive requirements standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ?? +125c param. no. symbol characteristic min. max. units conditions us125* t dt v2 ckl sync rcv (m aster and s lave ) data-hold before ck ? (dt hold time) 10 ? ns us126* t ck l2 dtl data-hold after ck ? (dt hold time) 15 ? ns * these parameters are characterized but not tested. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi sp70 sp71 sp72 sp73 sp74 sp75, sp76 sp78 sp79 sp80 sp79 sp78 msb lsb bit 6 - - - - - -1 msb in lsb in bit 6 - - - -1 note 1: refer to figure 23-2 for load conditions.
pic16(l)f720/721 ds41430d-page 206 ? 2010-2013 microchip technology inc. figure 23-16: spi master mode timing (cke = 1 , smp = 1 ) figure 23-17: spi slav e mode timing (cke = 0 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi sp81 sp71 sp72 sp74 sp75, sp76 sp78 sp80 msb sp79 sp73 msb in bit 6 - - - - - -1 lsb in bit 6 - - - -1 lsb note 1: refer to figure 23-2 for load conditions. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi sp70 sp71 sp72 sp73 sp74 sp75, sp76 sp77 sp78 sp79 sp80 sp79 sp78 msb lsb bit 6 - - - - - -1 msb in bit 6 - - - -1 lsb in sp83 note 1: refer to figure 23-2 for load conditions.
? 2010-2013 microchip technology inc. ds41430d-page 207 pic16(l)f720/721 figure 23-18: spi slav e mode timing (cke = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi sp70 sp71 sp72 sp82 sp74 sp75, sp76 msb bit 6 - - - - - -1 lsb sp77 msb in bit 6 - - - -1 lsb in sp80 sp83 note 1: refer to figure 23-2 for load conditions.
pic16(l)f720/721 ds41430d-page 208 ? 2010-2013 microchip technology inc. table 23-11: spi mode requirements param. no. symbol characteristic min. typ? max. units conditions sp70* t ss l2 sc h, t ss l2 sc l ss ? to sck ? or sck ? input t cy ??ns sp71* t sc h sck input high time (slave mode) t cy + 20 ? ? ns sp72* t sc l sck input low time (slave mode) t cy + 20 ? ? ns sp73* t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ? ns sp74* t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ? ns sp75* t do r sdo data output rise time 3.0-5.5v ? 10 25 ns 1.8-5.5v ? 25 50 ns sp76* t do f sdo data output fall time ? 10 25 ns sp77* t ss h2 do zss ? to sdo output high-impedance 10 ? 50 ns sp78* t sc r sck output rise time (master mode) 3.0-5.5v ? 10 25 ns 1.8-5.5v ? 25 50 ns sp79* t sc f sck output fall time (master mode) ? 10 25 ns sp80* t sc h2 do v, t sc l2 do v sdo data output valid after sck edge 3.0-5.5v ? ? 50 ns 1.8-5.5v ? ? 145 ns sp81* t do v2 sc h, t do v2 sc l sdo data output setup to sck edge tcy ? ? ns sp82* t ss l2 do v sdo data output valid after ss ? edge ? ? 50 ns sp83* t sc h2 ss h, t sc l2 ss h ss ?? after sck edge 1.5t cy + 40 ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 3.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested.
? 2010-2013 microchip technology inc. ds41430d-page 209 pic16(l)f720/721 figure 23-19: i 2 c? bus start/stop bits timing figure 23-20: i 2 c? bus data timing note 1: refer to figure 23-2 for load conditions. sp91 sp92 sp93 scl sda start condition stop condition sp90 table 23-12: i 2 c? bus start/stop bits requirements param. no. symbol characteristic min. typ max. units conditions sp90* t su : sta start condition 100 khz mode 4700 ? ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? ? sp91* t hd : sta start condition 100 khz mode 4000 ? ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? ? sp92* t su : sto stop condition 100 khz mode 4700 ? ? ns setup time 400 khz mode 600 ? ? sp93 t hd : sto stop condition 100 khz mode 4000 ? ? ns hold time 400 khz mode 600 ? ? * these parameters are characterized but not tested. note 1: refer to figure 23-2 for load conditions. sp90 sp91 sp92 sp100 sp101 sp103 sp106 sp107 sp109 sp109 sp110 sp102 scl sda in sda out
pic16(l)f720/721 ds41430d-page 210 ? 2010-2013 microchip technology inc. table 23-13: i 2 c? bus data requirements param. no. symbol characteristic min. max. units conditions 100* t high clock high time 100 khz mode 4.0 ? ? s device must operate at a minimum of 1.5 mhz 400 khz mode 0.6 ? ? s device must operate at a minimum of 10 mhz ssp module 1.5t cy ? 101* t low clock low time 100 khz mode 4.7 ? ? s device must operate at a minimum of 1.5 mhz 400 khz mode 1.3 ? ? s device must operate at a minimum of 10 mhz ssp module 1.5t cy ? 102* t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1c b 300 ns c b is specified to be from 10-400 pf 103* t f sda and scl fall time 100 khz mode ? 250 ns 400 khz mode 20 + 0.1c b 250 ns c b is specified to be from 10-400 pf 90* t su : sta start condition setup time 100 khz mode 4.7 ? ? s only relevant for repeated start condition 400 khz mode 0.6 ? ? s 91* t hd : sta start condition hold time 100 khz mode 4.0 ? ? s after this period the first clock pulse is generated 400 khz mode 0.6 ? ? s 106* t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 107* t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92* t su : sto stop condition setup time 100 khz mode 4.7 ? ? s 400 khz mode 0.6 ? ? s 109* t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110* t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmis- sion can start 400 khz mode 1.3 ? ? s c b bus capacitive loading ? 400 pf * these parameters are characterized but not tested. note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode (400 khz) i 2 c bus device can be used in a standard mode (100 khz) i 2 c bus system, but the requirement t su : dat ?? 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the scl line is released.
? 2010-2013 microchip technology inc. ds41430d-page 211 pic16(l)f720/721 24.0 dc and ac characteristics graphs and charts figure 24-1: pic16f720/721 max i dd vs. f osc over v dd , ec mode figure 24-2: pic16f720/721 typical i dd vs. f osc over v dd , ec mode 0 200 400 600 800 1000 1200 1400 1600 1800 0 2 4 6 8 1012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 5.0v 3.6v 3.0v 2.5v 1.8v 0 200 400 600 800 1000 1200 1400 1600 1800 0 2 4 6 8 1012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125 c) 5.0v 3.6v 3.0v 2.5v 1.8v
pic16(l)f720/721 ds41430d-page 212 ? 2010-2013 microchip technology inc. figure 24-3: pic16lf720/721 max. i dd vs. f osc over v dd , ec mode figure 24-4: pic16lf720/721 typical i dd vs. f osc over v dd , ec mode 0 200 400 600 800 1000 1200 1400 1600 1800 2000 0 2 4 6 8 1012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 2.0v 3.6v 3.0v 2.5v 1.8v 3.3v 0 200 400 600 800 1000 1200 1400 1600 1800 0 2 4 6 8 1012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 2.0v 3.6v 3.0v 2.5v 1.8v 3.3v
? 2010-2013 microchip technology inc. ds41430d-page 213 pic16(l)f720/721 figure 24-5: pic16f720/721 max. i dd vs. f osc over v dd , mfintosc figure 24-6: pic16f720/721 typical i dd vs. f osc over v dd , mfintosc 0 50 100 150 200 250 300 350 0 100 200 300 400 500 600 5v 3v 2.5v 1.8v f osc (kh z ) i dd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 50 100 150 200 250 300 350 0 100 200 300 400 500 600 5v 3v 2.5v 1.8v f osc (kh z ) i dd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
pic16(l)f720/721 ds41430d-page 214 ? 2010-2013 microchip technology inc. figure 24-7: pic16lf720/721 max. i dd vs. f osc over v dd , mfintosc figure 24-8: pic16lf720/721 typical i dd vs. f osc over v dd , mfintosc 0 50 100 150 200 250 0 100 200 300 400 500 600 3.6v 3v 2.5v 1.8v f osc (kh z ) i dd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 50 100 150 200 250 0 100 200 300 400 500 600 3.6v 3v 2.5v 1.8v f osc (kh z ) i dd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
? 2010-2013 microchip technology inc. ds41430d-page 215 pic16(l)f720/721 figure 24-9: pic16f720/721 max. i dd vs. f osc over v dd , hfintosc figure 24-10: pic16f720/721 typical i dd vs. f osc over v dd , hfintosc 0 200 400 600 800 1000 1200 1400 1600 1800 2000 024681012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 5.0v 3.6v 2.5v 1.8v 0 200 400 600 800 1000 1200 1400 1600 1800 2000 024681012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 5.0v 3.6v 2.5v 1.8v
pic16(l)f720/721 ds41430d-page 216 ? 2010-2013 microchip technology inc. figure 24-11: pic16lf720/721 max. i dd vs. f osc over v dd , hfintosc figure 24-12: pic16lf720/721 typical i dd vs. f osc over v dd , hfintosc 0 500 1000 1500 2000 2500 024681012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 3.6v 3.0v 2.5v 1.8v 0 200 400 600 800 1000 1200 1400 1600 1800 2000 024681012141618 i dd ( a) f osc (mhz) typical: statistical mean @25c maximum: mean (worst-case temp) +3  (-40c to 125c) 3.6v 3.0v 2.5v 1.8v
? 2010-2013 microchip technology inc. ds41430d-page 217 pic16(l)f720/721 figure 24-13: pic16f720/721 base i pd vs. v dd 0 10 20 30 40 50 60 70 80 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 typ. 25c max. 85c max.125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
pic16(l)f720/721 ds41430d-page 218 ? 2010-2013 microchip technology inc. figure 24-14: pic16lf720/721 maximum base i pd vs. v dd figure 24-15: pic16lf720/721 typical base i pd vs. v dd 0 1 2 3 4 5 6 7 8 1.5 2 2.5 3 3.5 4 max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 50 100 150 200 250 1.5 2 2.5 3 3.5 4 typ. v dd (v) i pd (na) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
? 2010-2013 microchip technology inc. ds41430d-page 219 pic16(l)f720/721 figure 24-16: pic16f720/721 wdt i pd vs. v dd figure 24-17: pic16lf720/721 wdt i pd vs. v dd 0 10 20 30 40 50 60 70 80 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 typ. 25c max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 2 4 6 8 10 12 14 1.5 2 2.5 3 3.5 4 typ. 25c max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
pic16(l)f720/721 ds41430d-page 220 ? 2010-2013 microchip technology inc. figure 24-18: pic16f720/721 fixed voltage reference i pd vs. v dd figure 24-19: pic16lf720/721 fixed voltage reference i pd vs. v dd 0 50 100 150 200 250 300 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 typ. max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 5 10 15 20 25 30 35 40 1.5 2 2.5 3 3.5 4 typ. max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
? 2010-2013 microchip technology inc. ds41430d-page 221 pic16(l)f720/721 figure 24-20: pic16f720/721 bor i pd vs. v dd figure 24-21: pic16lf720/721 bor i pd vs. v dd 0 10 20 30 40 50 60 70 80 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 typ. 25c max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c) 0 5 10 15 20 25 30 1.5 2 2.5 3 3.5 4 typ. 25c max. 85c max. 125c v dd (v) i pd (a) typical: statistical mean @25c maximum: mean (worst-case temp) +3 ? (-40c to 125c)
pic16(l)f720/721 ds41430d-page 222 ? 2010-2013 microchip technology inc. figure 24-22: ttl input threshold v in vs. v dd over temperature figure 24-23: schmitt trigger input threshold v in vs. v dd over temperature max. -40 typ. 25 min. 125 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 1.8 3.6 5.5 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) v in (v) v dd (v) typical: mean @25c v ih min. 125c 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 1.8 3.6 5.5 v in (v) v dd (v) v ih max. -40c maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c
? 2010-2013 microchip technology inc. ds41430d-page 223 pic16(l)f720/721 figure 24-24: schmitt trigger input threshold v in vs. v dd over temperature figure 24-25: v oh vs. i oh over temperature, v dd = 5.5v 0.0 0.5 1.0 1.5 2.0 2.5 3.0 1.8 3.6 5.5 v in (v) v dd (v) v il min. 125c v il max. -40c maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c max. -40 min. 125 typ. 25 5 5.1 5.2 5.3 5.4 5.5 5.6 -5.0 -4.2 -3.4 -2.6 -1.8 -1.0 -0.2 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c v oh (v) i oh (ma)
pic16(l)f720/721 ds41430d-page 224 ? 2010-2013 microchip technology inc. figure 24-26: v oh vs. i oh over temperature, v dd = 3.6v figure 24-27: v oh vs. i oh over temperature, v dd = 1.8v 2.6 2.8 3 3.2 3.4 3.6 3.8 -5.0 -4.2 -3.4 -2.6 -1.8 -1.0 -0.2 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c v oh (v) i oh (ma) max. -40 typ. 25 min. 125 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 v oh (v) i oh (ma) max. -40 typ. 25 min. 125 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c
? 2010-2013 microchip technology inc. ds41430d-page 225 pic16(l)f720/721 figure 24-28: v ol vs. i ol over temperature, v dd = 5.5v figure 24-29: v ol vs. i ol over temperature, v dd = 3.6 min. -40 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 5.0 6.0 7.0 8.0 9.0 10.0 v ol (v) i ol (ma) max. 125 typ. 25 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c min. -40 typ. 25 max. 125 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 4.0 5.0 6.0 7.0 8.0 9.0 10.0 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c v ol (v) i ol (ma)
pic16(l)f720/721 ds41430d-page 226 ? 2010-2013 microchip technology inc. figure 24-30: v ol vs. i ol over temperature, v dd = 1.8v figure 24-31: pic16f720/721 pwrt period 0 0.2 0.4 0.6 0.8 1 1.2 0.0 0.4 0.8 1.2 1.6 2.0 2.4 2.8 maximum: mean + 3 ? (-40c to 125c) minimum: mean - 3 ? (-40c to 125c) typical: mean @25c v ol (v) i ol (ma) max. 125 min. -40 max. -40c min. 125c 45 55 65 75 85 95 105 1.8v 2v 2.2v 2.4v 3v 3.6v 4v 4.5v 5v 5.5v time (ms) v dd typical: statistical mean @25c maximum: mean (worst-case temp) + 3 ? (-40c to 125c) typ. 25c
? 2010-2013 microchip technology inc. ds41430d-page 227 pic16(l)f720/721 figure 24-32: pic16f720/721 wdt time-out period figure 24-33: pic16f720/721 hfintosc wake-up from sleep start-up time typ. 25c max. -40c min. 125c 10.00 12.00 14.00 16.00 18.00 20.00 22.00 24.00 1.8v 2v 2.2v 2.4v 3v 3.6v 4v 4.5v 5v typical: statistical mean @25c maximum: mean (worst-case temp) + 3 ? (-40c to 125c) time (ms) v dd max. typ. 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 1.8v 2v 3v 3.6v 4v 4.5v 5v 5.5v typical: statistical mean @25c maximum: mean (worst-case temp) + 3 ? (-40c to 125c) time (us) v dd
pic16(l)f720/721 ds41430d-page 228 ? 2010-2013 microchip technology inc. figure 24-34: pic16f720/721 a/d internal rc oscillator period figure 24-35: typical fvr (x1 and x2) vs. supply voltage (v) normalized at 3.0v max. min. 0.0 1.0 2.0 3.0 4.0 5.0 6.0 1.8v 3.6v 5.5v typical: statistical mean @25c maximum: mean (worst-case temp) + 3 ? (-40c to 125c) period (s) v dd (v) -1.5 -1 -0.5 0 0.5 1 1.5 1.8 2.5 3 3.6 4.2 5.5 voltage percent change (%)
? 2010-2013 microchip technology inc. ds41430d-page 229 pic16(l)f720/721 figure 24-36: typical fvr change vs. temperature norm alized at 25c -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 -40 0 45 85 125 temperature (c) percent change (%)
pic16(l)f720/721 ds41430d-page 230 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 231 pic16(l)f720/721 25.0 packaging information 25.1 package marking information * standard picmicro ? device marking consists of microchip part number, year code, week code and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price. legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 20-lead pdip (300 mil) example xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn pic16f721-e/p 3 e 0810017 20-lead qfn (4x4x0.9 mm) example pin 1 pin 1 pic16 3 e e/ml 810017 f721
pic16(l)f720/721 ds41430d-page 232 ? 2010-2013 microchip technology inc. 25.1 package marking information * standard picmicro ? device marking consists of microchip part number, year code, week code and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price. legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 20-lead ssop (5.30 mm) example pic16f720 0810017 -i/ss 3 e 20-lead soic (7.50 mm) example pic16f720 -i/so 3 e 0810017
? 2010-2013 microchip technology inc. ds41430d-page 233 pic16(l)f720/721 25.2 package details the following sections give the technical details of the packages. 
    
     

     ),  )/%- ),'0 1'%2/*' 3%. %*. 4/2 3/2 4' -%2' 5)2+), 2+' +%2+' %*'%  6 )&,)1)%,2 +%*%2'*)2) 7 )3',),  %,   ,2 ),-/' 3- 1-%+ * $*2*/), - 1-%+ * $*2*/), +%-- ,2 '0'' 

8 $'* )' ! )3',),),& %, 2-'*%,),& $'*   !(  9 : 9%) )3',), +'*'2)%--. '0%2 %-/' +5, 5)2+/2 2-'*%,'   * 2+' 32 /**',2 $%;%&' *%5),& $-'%' '' 2+' )*+)$ %;%&),& $')1)%2), -%2' %2 +22$: 5553)*+)$3 $%;%&),& <,)2 => )3',), )3)2 = =  =/34'* 1 ), =
)2+ ' 
9  $ 2 '%2),& -%,'  ? ?  
-' %;%&' +);,'  ( 7
"( 9%' 2 '%2),& -%,'  
( ? ? +/-'* 2 +/-'* @)2+  7
7
7 ( -' %;%&' @)2+   !
 (
 a
'*%-- ',&2+  "a

7


)$ 2 '%2),& -%,'  ( 7
(
'% +);,'  
a 


( <$$'* '% @)2+ 4 
!( 



5'* '% @)2+ 4 
! 
a 
'*%-- 5 $%),& 6 '9 ? ? !7
n e1 note 1 d 123 a a1 a2 l e b1 b e c eb )*+)$ '+,-&. *%5),& 
!#
"9
pic16(l)f720/721 ds41430d-page 234 ? 2010-2013 microchip technology inc. 
   !  "  
#$ %  &'&'()    !     ),  )/%- ),'0 1'%2/*' 3%. %*. 4/2 3/2 4' -%2' 5)2+), 2+' +%2+' %*'%  %;%&' ) %5 ),&/-%2' 7 )3',),),& %, 2-'*%,),& $'*   !(  9 : 9%) )3',), +'*'2)%--. '0%2 %-/' +5, 5)2+/2 2-'*%,' : '1'*',' )3',), //%--. 5)2+/2 2-'*%,' 1* ),1*3%2), $/*$' ,-.   * 2+' 32 /**',2 $%;%&' *%5),& $-'%' '' 2+' )*+)$ %;%&),& $')1)%2), -%2' %2 +22$: 5553)*+)$3 $%;%&),& <,)2   )3',), )3)2 = =  =/34'* 1 ), =
)2+ '
(
9  '*%-- >')&+2 
a

"

2%,11 





( ,2%2 +);,' 7

 '*%-- @)2+  !
9  0$' % @)2+  

a
'*%-- ',&2+  !
9  0$' % ',&2+  

a
,2%2 @)2+ 4
a
 (
7
,2%2 ',&2+ 
7

!

(
,2%2#2#0$' % b

? ? d exposed pad e e2 2 1 n top view note 1 n l k b e d2 2 1 a a1 a3 bottom view )*+)$ '+,-&. *%5),& 
!# 9
? 2010-2013 microchip technology inc. ds41430d-page 235 pic16(l)f720/721   * 2+' 32 /**',2 $%;%&' *%5),& $-'%' '' 2+' )*+)$ %;%&),& $')1)%2), -%2' %2 +22$: 5553)*+)$3 $%;%&),&
pic16(l)f720/721 ds41430d-page 236 ? 2010-2013 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2010-2013 microchip technology inc. ds41430d-page 237 pic16(l)f720/721 note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic16(l)f720/721 ds41430d-page 238 ? 2010-2013 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2010-2013 microchip technology inc. ds41430d-page 239 pic16(l)f720/721 
  *+,# * -  **  .(   **-
     ),  )/%- ),'0 1'%2/*' 3%. %*. 4/2 3/2 4' -%2' 5)2+), 2+' +%2+' %*'%  )3',),  %,   ,2 ),-/' 3- 1-%+ * $*2*/), - 1-%+ * $*2*/), +%-- ,2 '0''

33 $'* )' 7 )3',),),& %, 2-'*%,),& $'*   !(  9 : 9%) )3',), +'*'2)%--. '0%2 %-/' +5, 5)2+/2 2-'*%,' : '1'*',' )3',), //%--. 5)2+/2 2-'*%,' 1* ),1*3%2), $/*$' ,-.   * 2+' 32 /**',2 $%;%&' *%5),& $-'%' '' 2+' )*+)$ %;%&),& $')1)%2), -%2' %2 +22$: 5553)*+)$3 $%;%&),& <,)2   )3',), )3)2 = =  =/34'* 1 ), =
)2+ '
( 9  '*%-- >')&+2  ? ? 
-' %;%&' +);,'  ( ( a( 2%,11 

( ? ? '*%-- @)2+  !
a
a
-' %;%&' @)2+  (
(7
(
'*%-- ',&2+  "

(
2 ',&2+ 
((
(
"( 2$*),2   (  '% +);,' 

" ?
 ( 2 ,&-'
c !c ac '% @)2+ 4
 ?
7a l l1 a2 c e b a1 a 12 note 1 e1 e d n )*+)$ '+,-&. *%5),& 
!#
 9
pic16(l)f720/721 ds41430d-page 240 ? 2010-2013 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2010-2013 microchip technology inc. ds41430d-page 241 pic16(l)f720/721 appendix a: data sheet revision history revision a (september 2010) original release of this document. revision b (march 2011) updated the electrical specifications section. revision c (september 2011) reviewed title; updated table 1 and table 1-1; reviewed the memory organization section; updated section 3.6, figures 3-4 and 3-5, register 4-1 and figure 4-2; updated registers 8-1 and 8-2; reviewed the oscillator module section; updated table 10-1, figures 11-1, 12-1 and register 18-1; updated the summary of registers tables; updated the electrical specifications section; updated the dc and ac characteristics graphs and charts section; updated the packaging information section; updated the product identification system section. revision d (february 2013) updated table 1-1, table 15-4 and table 16-5; updated the electrical specifications section; updated the dc and ac characteristics graphs and charts section; other minor corrections. appendix b: migrating from other pic ? devices this shows a comparison of features in the migration from another pic ? device, the pic16f720, to the pic16f721 device. b.1 pic16f690 to pic16f721 table b-1: feature comparison feature pic16f690 pic16f721 max. operating speed 20 mhz 16 mhz max. program memory (words) 4k 4k max. sram (bytes) 256 256 a/d resolution 10-bit 8-bit timers (8/16-bit) 2/1 2/1 oscillator modes 8 4 brown-out reset y y internal pull-ups ra<5:0>, rb<7:4> ra<5:0>, rb<7:4> interrupt-on-change ra<5:0>, rb<7:4> ra<5:0>, rb<7:4> comparator 2 0 eusart y y extended wdt y n software control option of wdt/bor yn intosc frequencies 31 khz - 8mhz 500 khz - 16 mhz pin count 20 20 note: this device has been designed to perform to the parameters of its data sheet. it has been tested to an electrical specification designed to determine its conformance with these parameters. due to process dif- ferences in the manufacture of this device, this device may have different perfor- mance characteristics than its earlier ver- sion. these differences may cause this device to perform differently in your appli- cation than the earlier version of this device. note: the user should verify that the device oscillator starts and performs as expected. adjusting the loading capacitor values and/or the oscillator mode may be required.
pic16(l)f720/721 ds41430d-page 242 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 243 pic16(l)f720/721 index a a/d specifications.................................................... 202, 203 absolute maximum ratings .............................................. 185 ac characteristics industrial and extended ............................................ 194 load conditions ........................................................ 193 adc .................................................................................... 75 acquisition requirements ........................................... 81 associated registers.................................................... 83 block diagram............................................................. 75 calculating acquisition time....................................... 81 channel selection....................................................... 76 configuration............................................................... 76 configuring interrupt ................................................... 78 conversion clock........................................................ 76 conversion procedure ................................................ 78 internal sampling switch (r ss ) impedance................ 81 interrupts..................................................................... 77 operation .................................................................... 77 operation during sleep .............................................. 78 port configuration ....................................................... 76 source impedance...................................................... 81 special event trigger.................................................. 78 adcon0 register......................................................... 16, 79 adcon1 register......................................................... 17, 80 addressable universal synchronous asynchronous receiver transmitter (ausart)............................... 117 adres register ................................................................. 80 adresh register............................................................... 16 analog-to-digital converter. see adc ansela register ............................................................... 47 anselb register ............................................................... 56 assembler mpasm assembler................................................... 182 ausart ........................................................................... 117 associated registers baud rate generator........................................ 127 asynchronous mode ................................................. 119 associated registers receive..................................................... 124 transmit.................................................... 121 baud rate generator (brg) ............................ 127 receiver............................................................ 121 setting up 9-bit mode with address detect....... 123 transmitter........................................................ 119 baud rate generator (brg) baud rate error, calculating ............................ 127 baud rates, asynchronous modes .................. 128 formulas ........................................................... 127 high baud rate select (brgh bit) .................. 127 synchronous master mode ............................... 130, 134 associated registers receive..................................................... 133 transmit.................................................... 131 reception.......................................................... 132 transmission .................................................... 130 synchronous slave mode associated registers receive..................................................... 135 transmit.................................................... 134 reception.......................................................... 135 transmission .................................................... 134 b bf bit ........................................................................ 145, 157 block diagrams (ccp) capture mode operation ............................... 108 adc ............................................................................ 75 adc transfer function ............................................... 82 analog input model..................................................... 82 ausart receive ..................................................... 118 ausart transmit .................................................... 117 ccp pwm ................................................................ 112 clock source .............................................................. 65 compare................................................................... 110 interrupt logic............................................................. 35 mclr circuit .............................................................. 27 on-chip reset circuit................................................. 25 ra0 pins..................................................................... 49 ra1 pins..................................................................... 50 ra2 pin ...................................................................... 51 ra4 pin ...................................................................... 52 ra5 pin ................................................................ 52, 53 rb0 pin ...................................................................... 57 rb3 pin ...................................................................... 58 rc0 pin ...................................................................... 62 rc5 pin ...................................................................... 63 rc6 pin ...................................................................... 63 rc7 pin ...................................................................... 63 spi mode.................................................................. 138 ssp (i 2 c mode)........................................................ 147 timer1 .................................................. 93, 99, 100, 101 timer2 ...................................................................... 105 tmr0/wdt prescaler ................................................ 89 voltage reference...................................................... 85 brown-out reset (bor)...................................................... 29 timing and characteristics ....................................... 199 c c compilers mplab c18 .............................................................. 182 capture module. see capture/compare/pwm (ccp) capture/compare/pwm (ccp) ........................................ 107 associated registers w/ capture............................... 109 associated registers w/ compare............................. 111 associated registers w/ pwm................................... 115 capture mode ........................................................... 108 ccpx pin configuration............................................ 108 compare mode ......................................................... 110 ccpx pin configuration.................................... 110 software interrupt mode ........................... 108, 110 special event trigger ....................................... 110 timer1 mode selection............................. 108, 110 prescaler .................................................................. 108 pwm mode............................................................... 112 duty cycle ........................................................ 113 effects of reset ................................................ 114 example pwm frequencies and resolutions 16 mhz..................................................... 114 8 mhz ....................................................... 114 operation in sleep mode.................................. 114 setup for operation .......................................... 114 system clock frequency changes .................. 114 pwm period ............................................................. 113 setup for pwm operation ........................................ 114 timer resources ...................................................... 107
pic16(l)f720/721 ds41430d-page 244 ? 2010-2013 microchip technology inc. ccp. see capture/compare/pwm (ccp) ccp1con register ............................................................ 16 ccpr1h register ............................................................... 16 ccpr1l register................................................................ 16 ccpxcon register .......................................................... 107 cke bit ...................................................................... 145, 157 ckp bit ...................................................................... 144, 156 clock sources external modes ........................................................... 69 ec ....................................................................... 69 code examples a/d conversion ........................................................... 78 call of a subroutine in page 1 from page 0................ 23 changing between capture prescalers .................... 108 indirect addressing ..................................................... 24 initializing porta....................................................... 45 initializing portb....................................................... 54 initializing portc....................................................... 60 loading the sspbuf (sspsr) register .................. 140 saving w, status and pclath registers in ram ................................................................ 37 writing to flash program memory ............................ 163 comparators c2out as t1 gate ..................................................... 95 compare module. see capture/compare/pwm (ccp) customer change notification service ............................. 249 customer notification service........................................... 249 customer support ............................................................. 249 d d/a bit ............................................................................... 157 data memory....................................................................... 12 data/address bit (d/a ) ...................................................... 157 dc and ac characteristics ............................................... 211 dc characteristics extended and industrial ............................................ 190 industrial and extended ............................................ 186 development support ....................................................... 181 device configuration........................................................... 71 code protection .......................................................... 74 configuration word ..................................................... 71 user id ........................................................................ 74 device overview ................................................................... 7 e effects of reset pwm mode ............................................................... 114 electrical specifications .................................................... 185 errata .................................................................................... 6 f firmware instructions........................................................ 171 fixed voltage reference. see fvr fsr register................................................................. 16, 17 fvr ..................................................................................... 85 associated registers.................................................... 86 fvrcon register............................................................... 86 g general purpose register file............................................ 13 i i 2 c mode associated registers ................................................ 158 indf register ............................................................... 16, 17 indirect addressing, indf and fsr registers.................... 24 instruction format............................................................. 171 instruction set................................................................... 171 addlw..................................................................... 173 addwf..................................................................... 173 andlw..................................................................... 173 andwf..................................................................... 173 movf ....................................................................... 176 bcf .......................................................................... 173 bsf........................................................................... 173 btfsc ...................................................................... 173 btfss ...................................................................... 174 call......................................................................... 174 clrf ........................................................................ 174 clrw ....................................................................... 174 clrwdt .................................................................. 174 comf ....................................................................... 174 decf ........................................................................ 174 decfsz ................................................................... 175 goto ....................................................................... 175 incf ......................................................................... 175 incfsz..................................................................... 175 iorlw ...................................................................... 175 iorwf...................................................................... 175 movlw .................................................................... 176 movwf .................................................................... 176 nop .......................................................................... 176 retfie ..................................................................... 177 retlw ..................................................................... 177 return................................................................... 177 rlf ........................................................................... 178 rrf .......................................................................... 178 sleep ...................................................................... 178 sublw ..................................................................... 178 subwf..................................................................... 179 swapf ..................................................................... 179 xorlw .................................................................... 179 xorwf .................................................................... 179 summary table ........................................................ 172 intcon register................................................................ 38 internal oscillator block intosc specifications ........................................... 197, 198 internal sampling switch (r ss ) impedance........................ 81 internet address ............................................................... 249 interrupts............................................................................. 35 adc ............................................................................ 78 associated registers w/ interrupts............................... 41 interrupt-on-change ................................................... 54 tmr1 .......................................................................... 98 intosc specifications ............................................. 197, 198 iocb register..................................................................... 56 l load conditions................................................................ 193 m m....................................................................................... 201 mclr .................................................................................. 27 internal........................................................................ 27 memory organization ......................................................... 11 data ............................................................................ 12 program ...................................................................... 11 microchip internet web site.............................................. 249 migrating from other pic microcontroller devices ............ 241 mplab asm30 assembler, linker, librarian ................... 182 mplab integrated development environment software.. 181
? 2010-2013 microchip technology inc. ds41430d-page 245 pic16(l)f720/721 mplab pm3 device programmer .................................... 184 mplab real ice in-circuit emulator system................. 183 mplink object linker/mplib object librarian ................ 182 o opcode field descriptions ............................................. 171 option_reg register ...................................................... 91 osccon register.............................................................. 67 oscillator associated registers............................................ 69, 104 oscillator module ec ............................................................................... 65 oscillator tuning ......................................................... 68 oscillator parameters ....................................................... 197 oscillator specifications.................................................... 196 osctune register ............................................................ 68 p p (stop) bit ........................................................................ 157 packaging ......................................................................... 231 marking ............................................................. 231, 232 pdip details.............................................................. 233 paging, program memory ................................................... 23 pcl and pclath ............................................................... 23 computed goto........................................................ 23 stack ........................................................................... 23 pcl register................................................................. 16, 17 pclath register ......................................................... 16, 17 pcon register ....................................................... 17, 22, 30 pie1 register................................................................ 17, 39 pir1 register................................................................ 16, 40 pmadrh register ............................................................ 165 pmadrl register............................................................. 166 pmcon1 register .................................................... 164, 166 pmdath register ............................................................ 165 pmdatl register ............................................................. 165 porta................................................................................ 45 ansela register ....................................................... 47 associated registers .................................................. 53 pin descriptions and diagrams................................... 48 porta register ......................................................... 16 ra0 ............................................................................. 48 ra1 ............................................................................. 48 ra2 ............................................................................. 48 ra3 ............................................................................. 48 ra4 ............................................................................. 48 ra5 ............................................................................. 48 ra6 ............................................................................. 48 specifications............................................................ 198 porta register ................................................................. 46 portb additional pin functions anselb register ............................................... 54 weak pull-up ...................................................... 54 associated registers .................................................. 59 interrupt-on-change.................................................... 54 pin descriptions and diagrams................................... 57 portb register ......................................................... 16 rb0 ............................................................................. 57 rb4 ............................................................................. 57 rb5 ............................................................................. 57 rb6 ............................................................................. 57 rb7 ............................................................................. 57 portb register ................................................................. 55 portc portc register ......................................................... 16 rc0 ............................................................................ 62 rc2 ............................................................................ 62 rc3 ............................................................................ 62 rc4 ............................................................................ 62 rc5 ............................................................................ 62 rc6 ............................................................................ 62 rc7 ............................................................................ 62 specifications ........................................................... 198 portc register................................................................. 60 power-down mode (sleep)............................................... 167 associated registers................................................ 168 power-on reset .................................................................. 27 power-up timer (pwrt) .................................................... 27 specifications ........................................................... 200 pr2 register .............................................................. 17, 146 precision internal oscillator parameters .......................... 198 prescaler shared wdt/timer0................................................... 90 product identification system ........................................... 251 program memory ................................................................ 11 map and stack (pic16f720/lf720) ........................... 11 map and stack (pic16f721/lf721) ........................... 11 paging ........................................................................ 23 program memory read (pmr) ......................................... 159 associated registers................................................ 166 programming, device instructions.................................... 171 r r/w bit.............................................................................. 157 rcreg............................................................................. 123 rcsta register ......................................................... 16, 126 reader response............................................................. 250 read-modify-write operations ......................................... 171 receive overflow indicator bit (sspov) .................. 144, 156 registers adcon0 (adc control 0) .......................................... 79 adcon1 (adc control 1) .......................................... 80 adres (adc result) ................................................. 80 ansela (porta analog select) .............................. 47 anselb (portb analog select) .............................. 56 ccpxcon (ccp operation) .................................... 107 fvrcon (fixed voltage reference register) ........... 86 intcon (interrupt control) ........................................ 38 iocb (interrupt-on-change portb).......................... 56 option_reg (option) .............................................. 91 osccon (oscillator control)..................................... 67 osctune (oscillator tuning).................................... 68 pcon (power control register)................................. 22 pcon (power control) ............................................... 30 pie1 (peripheral interrupt enable 1) .......................... 39 pir1 (peripheral interrupt register 1) ........................ 40 pmadrh (program memory address high) ............ 165 pmadrl (program memory address low).............. 166 pmcon1 (program memory control 1) ................... 164 pmdath (program memory data high) .................. 165 pmdatl (program memory data low).................... 165 porta ....................................................................... 46 portb ....................................................................... 55 portc ....................................................................... 60 rcsta (receive status and control) ...................... 126 reset values .............................................................. 32 reset values (special registers)............................... 34 sspcon (sync serial port c ontrol) register .. 144, 156 sspstat (sync serial port status) register .. 145, 157 status ..................................................................... 20 t1con (timer1 control) .......................................... 102
pic16(l)f720/721 ds41430d-page 246 ? 2010-2013 microchip technology inc. t1gcon (timer1 gate control) ............................... 103 t2con ...................................................................... 106 trisa (tri-state porta) ........................................... 46 trisb (tri-state portb) ........................................... 55 trisc (tri-state portc) .......................................... 61 txsta (transmit status and control) ...................... 125 wpub (weak pull-up portb) ................................... 55 reset................................................................................... 25 resets associated registers .................................................. 34 revision history ................................................................ 241 s s (start) bit ........................................................................ 157 smp bit...................................................................... 145, 157 software simulator (mplab sim)..................................... 183 spbrg.............................................................................. 127 spbrg register ................................................................. 17 special event trigger.......................................................... 78 special function registers ................................................. 13 spi mode .......................................................................... 143 associated registers ................................................ 146 typical master/slave connection ............................. 137 ssp ................................................................................... 137 i 2 c mode ................................................................... 147 acknowledge..................................................... 148 addressing ........................................................ 149 clock stretching................................................ 154 clock synchronization ...................................... 155 firmware master mode ..................................... 154 hardware setup ................................................ 147 multi-master mode ............................................ 154 reception.......................................................... 150 sleep operation ................................................ 155 start/stop conditions ........................................ 148 transmission..................................................... 152 master mode ............................................................. 139 spi mode .................................................................. 137 slave mode ....................................................... 141 typical spi master/slave connection....................... 137 sspadd register ............................................................... 17 sspbuf register ............................................................... 16 sspcon register............................................... 16, 144, 156 sspen bit ................................................................. 144, 156 sspm bits ................................................................. 144, 156 sspov bit ................................................................. 144, 156 sspstat register ............................................. 17, 145, 157 status register................................................................ 20 synchronous serial port enable bit (sspen)........... 144, 156 synchronous serial port mode select bits (sspm) .. 144, 156 t t1con register.......................................................... 16, 102 tmr1on bit.............................................................. 103 t1gcon register............................................................. 103 t2con register.................................................. 16, 106, 146 temperature indicator module ............................................ 87 thermal considerations .................................................... 192 time-out sequence............................................................. 30 timer0 ................................................................................. 89 associated registers .................................................. 91 operation .............................................................. 89, 94 specifications............................................................ 201 timer1 ................................................................................. 93 associated registers.................................................. 104 asynchronous counter mode ..................................... 95 reading and writing ........................................... 95 interrupt ...................................................................... 98 modes of operation .................................................... 94 module on/off (tmr1on bit)................................... 103 operation during sleep .............................................. 98 prescaler .................................................................... 95 specifications ........................................................... 201 timer1 gate selecting source ................................................ 95 tmr1h register ......................................................... 93 tmr1l register.......................................................... 93 timer2 associated registers ................................................. 106 timers timer1 t1con ............................................................. 102 t1gcon........................................................... 103 timer2 t2con ............................................................. 106 timing diagrams a/d conversion......................................................... 203 a/d conversion (sleep mode) .................................. 204 asynchronous reception.......................................... 124 asynchronous transmission..................................... 120 asynchronous transmission (back-to-back)............ 121 brown-out reset (bor)............................................ 199 brown-out reset situations ........................................ 29 clkout and i/o ...................................................... 198 clock synchronization .............................................. 155 clock timing ............................................................. 196 i 2 c bus data............................................................. 209 i 2 c bus start/stop bits ............................................. 209 i 2 c reception (7-bit address)................................... 150 i 2 c slave mode with sen = 0 (reception, 10-bit address) ................................................. 151 i 2 c transmission (7-bit address).............................. 152 int pin interrupt ......................................................... 36 slave select synchronization ................................... 143 spi master mode ...................................................... 140 spi master mode (cke = 1, smp = 1) ..................... 206 spi mode (slave mode with cke = 0)...................... 142 spi mode (slave mode with cke = 1)...................... 142 spi slave mode (cke = 0) ....................................... 206 spi slave mode (cke = 1) ....................................... 207 synchronous reception (master mode, sren) ....... 133 synchronous transmission ...................................... 131 synchronous transmission (through txen) ........... 131 time-out sequence case 1 ................................................................ 30 case 2 ................................................................ 31 case 3 ................................................................ 31 timer0 and timer1 external clock ........................... 200 timer1 incrementing edge ......................................... 98 usart synchronous receive (master/slave) ......... 205 usart synchronous transmission (master/slave). 204 wake-up from interrupt............................................. 168 timing parameter symbology .......................................... 193 timing requirements i 2 c bus data............................................................. 210 i2c bus start/stop bits............................................. 209 spi mode .................................................................. 208 tmr0 register.................................................................... 16 tmr1h register ................................................................. 16 tmr1l register.................................................................. 16 tmr2 register.................................................................... 16
? 2010-2013 microchip technology inc. ds41430d-page 247 pic16(l)f720/721 tmro register ................................................................... 18 trisa ................................................................................. 45 trisa register ............................................................. 17, 46 trisb ................................................................................. 54 trisb register ............................................................. 17, 55 trisc ................................................................................. 60 trisc register............................................................. 17, 61 txreg.............................................................................. 119 txreg register ................................................................. 16 txsta register .......................................................... 17, 125 brgh bit .................................................................. 127 u ua ..................................................................................... 157 update address bit, ua .................................................... 157 usart synchronous master mode requirements, synchronous receive .............. 205 requirements, synchronous transmission ...... 204 timing diagram, synchronous receive ........... 205 timing diagram, synchronous transmission ... 204 w wake-up using interrupts ................................................. 168 watchdog timer (wdt) ...................................................... 27 clock source............................................................... 27 modes ......................................................................... 28 period.......................................................................... 27 specifications............................................................ 200 wcol bit .................................................................. 144, 156 wpub register................................................................... 55 write collision detect bit (wcol)............................. 144, 156 www address.................................................................. 249 www, on-line support ....................................................... 6
pic16(l)f720/721 ds41430d-page 248 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 249 pic16(l)f720/721 the microchip web site microchip provides online support via our www site at www.microchip.com . this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com . under ?support?, click on ?customer change notification? and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://microchip.com/support
pic16(l)f720/721 ds41430d-page 250 ? 2010-2013 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to: technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds41430d pic16(l)f720/721 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2010-2013 microchip technology inc. ds41430d-page 251 pic16(l)f720/721 product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device: pic16f720, pic16lf720, pic16f721, pic16lf721 temperature range: i= -40 ? c to +85 ? c e= -40 ? c to +125 ? c package: ml = micro lead frame (qfn) p = plastic dip so = soic ss = ssop pattern: 3-digit pattern code for qtp (blank otherwise) examples: a) pic16f720-e/p 301 = extended temp., pdip package, qtp pattern #301 b) pic16f721t-i/so = tape and reel, industrial temp., soic package note 1: t= available in tape and reel for all industrial devices except pdip. 2: tape and reel identifier only appears in the catalog part number description. this identifier is used for ordering purposes and is not printed on the device package. check with your microchip sales office for package availability with the tape and reel option. x (1) tape and reel option
pic16(l)f720/721 ds41430d-page 252 ? 2010-2013 microchip technology inc. notes:
? 2010-2013 microchip technology inc. ds41430d-page 253 information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, flashflex, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, pic 32 logo, rfpic, sst, sst logo, superflash and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mtp, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. silicon storage technology is a registered trademark of microchip technology inc. in other countries. analog-for-the-digital age, app lication maestro, bodycom, chipkit, chipkit logo, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mpf, mplab certified logo, mplib, mplink, mtouch, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, real ice, rflab, select mode, sqi, serial quad i/o, total endurance, tsharc, uniwindriver, wiperlock, zena and z-scale are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. gestic and ulpp are registered trademarks of microchip technology germany ii gmbh & co. & kg, a subsidiary of microchip technology inc., in other countries. all other trademarks mentioned herein are property of their respective companies. ? 2010-2013, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. isbn: 9781620769997 note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconduc tor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvin g the code protection features of our products. attempts to break microchip?s code protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified. quality management s ystem certified by dnv == iso/ts 16949 ==
ds41430d-page 254 ? 2010-2013 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://www.microchip.com/ support web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 indianapolis noblesville, in tel: 317-773-8323 fax: 317-773-5453 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8569-7000 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - chongqing tel: 86-23-8980-9588 fax: 86-23-8980-9500 china - hangzhou tel: 86-571-2819-3187 fax: 86-571-2819-3189 china - hong kong sar tel: 852-2943-5100 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8864-2200 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4123 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - osaka tel: 81-6-6152-7160 fax: 81-6-6152-9310 japan - tokyo tel: 81-3-6880- 3770 fax: 81-3-6880-3771 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-5778-366 fax: 886-3-5770-955 taiwan - kaohsiung tel: 886-7-213-7828 fax: 886-7-330-9305 taiwan - taipei tel: 886-2-2508-8600 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 worldwide sales and service 11/29/12


▲Up To Search▲   

 
Price & Availability of PIC16F72013

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X